Chat UIKit SwiftUI v3
Chat UIKit SwiftUI
Chat UIKit
SwiftUI
Version 3

List channels

Copy link

The GroupChannelListView is a struct that is used to build a group channel list view. When there is no connection between the client app and Sendbird server, this struct is automatically called to reconnect the two. Once the client app is connected to Sendbird server, the struct is called and a list of channels in the client app is displayed. GroupChannelListView also handles core features including pagination and real-time updates. In many cases, the channel list is a good place to start your chat service.


Features

Copy link

Refer to the table below to see what features are available in GroupChannelListView.

FeatureDescription

Enter a channel

Allows users to enter a group channel by selecting a channel row on the list.

Turn on/off notifications

Turns push notifications on or off by swiping on the channel row of the group channel.

Create channel

Creates a new group channel.

Select channel type

Allows users to select the channel type when creating a new group channel (group channel, super group channel, braodcast channel).

Leave channel

Allows users to leave a channel by swiping on the channel row they wish to leave.

Go back to previous view or dismiss current view

Allows users to go back to the previous view from the navigation stack or dismisses the current view.

Show delivery receipt

Displays the delivery receipt status in the channel row when the last message was sent by the current user. This feature is not turned on by default. To learn how to show the delivery receipt in a channel list, go to the delivery receipt feature page.

Show read receipt

Displays the read receipt in the channel row when the last message was read by the current user. This feature is not turned on by default. To learn how to show the read receipt in a channel list, go to the read receipt feature page.

Show typing indicator

Displays in the channel row whether another user in the channel is typing a message. This feature is not turned on by default. To learn how to show the typing indicator in a channel list, go to the typing indicator feature page.


Initialize

Copy link

You can start building a channel list view by initializing the GroupChannelListView struct.

Note: You can set the channelListQuery object when initializing GroupChannelListView. Otherwise, the default value is used.

import SwiftUI
import SendbirdSwiftUI
import SendbirdChatSDK

struct ContentView: View {
    var channelListQuery: GroupChannelListQuery
    
    init() {
        let params = GroupChannelListQueryParams()
        params.limit = 30
        params.includeEmptyChannel = false
        params.includeFrozenChannel = true
        self.channelListQuery = GroupChannel.createMyGroupChannelListQuery(params: params)
    }
    
    var body: some View {
        GroupChannelListView(channelListQuery: self.channelListQuery)
        // or simply call `GroupChannelListView()` for default behavior.
    }
}

Init parameters

Copy link
ParameterTypeRequired

channelListQuery

GroupChannelListQuery

x


Customization

Copy link

Sendbird Chat SwiftUI provides a View customization and DestinationViewBuilder.

  • View customization: Our SwiftUI SDK allows you to selectively customize view elements. To learn more about the customization and our SwiftUI is designed, see the customization guide.
  • DestinationViewBuilder: Use DestinationViewBuilder to customize the destination views that are navigatable from the group channel view.

Note : Visit our Github Sample to see the custom sample implementation for each item.

Partial customization

Copy link

You can easily customize a specific part of a View, which particularly comes in handy when changing only a certain area in the View. To do so, use the View Builders that Sendbird has predefined and its a ViewConfig. The ViewConfig contains the data needed to render the view and its parameters can be found in the table below.

Parameter

Copy link
ParameterTypeView builders

headerItem

() -> GroupChannelListType.HeaderItem

leftView
titleView
headerView

listItem

() -> GroupChannelListType.ListItem

rowView
- channelName
- channelPreivew
- coverImage
- unreadCount

The following code demonstrates how to replace the view items using headerItem. All other {Component}Items can be used in the same way.

Note : When you customize a parent view, customizations in the child views will not be applied. For example, if you customize the titleView in the headerItem, the customizations of the coverImage or titleLabel in the lower view items will not be applied.

GroupChannelListView(
    headerItem: {
        .init()
        .titleView { viewConfig in
            Text("My Group Channels")
                .fontWeight(.bold)
        }
    }
)

Full customization

Copy link

You can also customize the entire view area as desired. You simply need to return a SwiftUI View in the closure. The ViewConfig contains the data needed to render the view. Its parameters can be found in the table below.

Parameter

Copy link
ParameterTypeView builders

list

(ViewConfig) -> some View

-

The following code demonstrates how to replace the entire list area using the list parameter.

Note : When you customize a parent view, customizations in the child views will not be applied. For example, if you customize the entire area through the list, the customizations set in the listItem will not be applied.

GroupChannelListView(
    list: { viewConfig in
        ScrollView {
            ForEach(viewConfig.channels) { channel in
                VStack {
                    Text("Custom Title")
                }
            }
        }
    }
)

Note: The messages in viewConfig are sorted in descending timestamp. This means that the latest message appears first in the array.

DestinationViewBuilder

Copy link

Sendbird Chat SwiftUI is designed to internally navigate from each view to its connected view. However, if you need to customize the destination view, you can do so by using the interface provided by the DestinationViewBuilder.

DestinationViewBuilder method

Copy link
MethodViewBuilder Type

createChannelView

CreateGroupChannelViewBuilder

groupChannelView

GroupChannelViewBuilder

The following code demonstrates how to replace the channel settings view connected from the channel view.

GroupChannelListView()
.groupChannelView { channelURL, startingPoint, messageListParams in
    // Customize the messageListParams.
    messageListParams?.previousResultSize = 30
    messageListParams?.replyType = .onlyReplyToChannel
    messageListParams?.includeParentMessageInfo = true
    
    return GroupChannelView(
        channelURL: channelURL,
        startingPoint: startingPoint,
        messageListParams: messageListParams
    )
    // you can also add view adaptors to GroupChannelView.
}

Note : If you've customized a child view of another view, you need to set the destination view for all the views from the top to the destination view.