Skip to main content
CometChatGroups lists the groups in your app. Each row shows the group’s avatar with a badge for private and password-protected groups, its name and its member count. A tap opens a group the user is in and joins a public one first. The list paginates as you scroll, updates in real time and searches the server as you type in its search field.
CometChatGroups showing groups with type badges and member counts

Where It Fits

CometChatGroups is the screen a user opens to find a group to chat in, or the picker a “share to groups” flow embeds. It hands you the selected Group through onItemClick; open your message screen with it.
Both toolkits read from the same store, so the SwiftUI and UIKit lists can never disagree about what to show.

Quick Start

The list draws a system navigation bar with a large title, so it brings its own NavigationStack. If your screen already has one, pass embedsNavigationStack: false. The search field is in the bar by default; pass hideSearchBox: true to leave it out.
That is a working list: it fetches the first page and paginates as you scroll. onItemClick hands you a CometChatSDK.Group: one the user is a member of, or a password-protected one they have not joined yet — check hasJoined. Prerequisites: the Kit initialised with CometChatSession.initialize, a user logged in, and the package added. See Getting Started.

What a Tap Does

Outside selection mode a tap depends on the group. If the join fails onError is called and nothing else happens: there is no alert and no error screen. A successful join is announced on the Kit’s event bus as a member-joined event, so the Kit’s other components follow.

Filtering Groups

Two builders: one for browsing, one used while a search is active.
Both builders are used from the first page. With no search builder, a search runs on your list builder with the keyword added, and the keyword is taken off again afterwards. Giving the list a different list builder after it has loaded replaces the list with that builder’s first page.
A search runs 0.6 s after the last keystroke and shows one page of results in place of the list. Clearing the field shows the loaded list again without a request.

Filter Recipes


Actions and Events

Callback Methods

Setting onItemLongClick replaces the options menu: a long press calls it instead of opening the row’s options.
onLoad is called with the loaded list — not a search’s result — each time it changes. onError is called for every failure. The error state is shown when nothing is loaded, and also when the next page fails with rows on screen — it takes their place. A failed refresh or search with rows on screen leaves them there. Retry reloads the first page. A failed join is reported to onError and shows nothing.

SDK Events (Real-Time, Automatic)

No wiring required — the store listens and the list updates itself. The first page is also fetched again, and replaces the list when it arrives, on pull-to-refresh. The list does not reload when the screen re-appears. Removing the last group leaves a blank list: the empty state is for the server answering with no groups, or a search finding none.

Functionality

hideToolbar hides the navigation bar, and the search field with it. hideToolbarSeparator, passwordGroupIcon and privateGroupIcon draw nothing; set the badge’s glyphs through itemStyle.statusIndicatorStyle.

Custom View Slots

Every slot is available as an initialiser argument and as a modifier that cascades to every CometChatGroups below it. Supply both and the initialiser argument wins.
Slot closures receive a ChatGroup — the row’s value type (id, name, type, membersCount, hasJoined, scope, ownerUID).

The list has no options of its own. Give it some and each row shows them twice: as trailing swipe actions and as a long-press menu.
options come first and the added options after them; both lists are shown.

Common Patterns

Join a password-protected group

A password group comes to onItemClick like any other: check hasJoined, ask for the password and join through the store.
The store’s join(_:password:) returns the joined group, or nil after calling onError — a wrong password is reported there and nowhere else.

Scope buttons under the search field

.cometChatSearchScopes(_:selection:) puts scope buttons under the search field, in the navigation bar, as a New Chat screen switches between Users and Groups. The rows scroll under the field and the buttons with the bar’s soft edge, and the large title stays sharp.The buttons show whether or not the field is being searched, and they don’t filter the search: the list only reports the selection, and what it means is up to you. The modifier applies to every list under it, so when your screen swaps one list for the other, the buttons stay in the bar with the right one selected.

Advanced Methods

Selection

Tapping rows fills selected.
In selection mode a tap selects or deselects, and nothing is joined. If you set onItemClick it is called as well, before the selection changes. onSelection is called with the whole selection on every change. In .single mode a second tap on the selected row deselects it. A .multiple selection has no limit. Once something is selected the navigation bar shows the count with a cross and a tick. The tick calls onSelectedItemProceed with the selected groups and leaves the selection and the mode as they are. The cross clears the selection; the mode stays on, so the next tap selects again.

Store Access

GroupsStore also exposes join(_:password:), search(_:), fetchGroups(), retry() and the list operations addItem, insertItem, removeItem, updateItem, moveItemToTop and clearItems.

Subclassing

CometChatGroups is a View struct. Customise it with its slots, modifiers and style.

Style

Unset properties fall through to the theme, so a style carries only what you change.
On iOS 26 the navigation bar is Liquid Glass and the Kit leaves it to the system. Below iOS 26, or with Reduce Transparency on, the bar is filled with the list’s background. Setting navigationBarBackgroundColor fills it everywhere.
The title, the back button’s glyph and the search field belong to the system’s navigation bar; the style properties for them have no effect.

Next Steps

Group Members

List and manage the members of a group

Message List

Show the messages of the group a tap opens

Group Chat

Create, join and manage groups

Component Styling

Style every component