Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,34 @@
title: Channel List Search
---

By default, the channel list component shows a search bar at the top. This component lets you search through messages matching the search term inside the channels. When you tap on a search result, the corresponding channel is opened, automatically scrolling to the searched message.
### Basic Usage

The channel list component shows a search bar at the top that lets you search through messages or channels depending on the `searchType` provided when creating the `ChatChannelListView` component. By default, the search type is set to `.messages`, which means that the search will be performed on messages inside the channels and threads.

If you want to change the search type to `.channels`, you can do so by setting the `searchType` parameter when creating the `ChatChannelListView` component:

```swift
ChatChannelListView(
viewFactory: CustomAppFactory.shared,
searchType: .channels
)
```

:::note
The `searchType` parameter is only available on the SwiftUI SDK since version [4.66.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.66.0).
:::

### Navigation

When a user taps on a search result, the corresponding channel is opened, automatically scrolling to the searched message or channel depending on the `searchType`.

The SwiftUI components can also scroll to a message that is not available in the local database at that moment. In those cases, the messages around that message are also loaded. The scrolling in these cases can happen in both directions - up (for loading older messages) and down (for loading newer messages).

You can also search for messages that are part of message threads. In those cases, first the channel is opened, and then the corresponding message thread is shown, scrolling to the searched message.

In order to replace this component with your own (or completely remove it by returning an EmptyView), you need to implement the `makeChannelListTopView` method:
### Search Bar

In order to replace the search bar with your own (or completely remove it by returning an EmptyView), you need to implement the `makeChannelListTopView` method:

```swift
func makeChannelListTopView(
Expand All @@ -22,7 +43,7 @@ In this method, a binding of the search text is provided, in case you want to im

### Message Search Controller

Under the hood, the channel list search uses the `MessageSearchController`, that you can also use to provide search in your custom UI components.
Under the hood, the channel list search uses the `MessageSearchController` when the `searchType` is set to `.messages`, so that you can also use it to provide search in your custom UI components.

Here's an example how to search for a particular search text:

Expand Down
Loading