Skip to main content
CometChatUsers lists the users in your app, grouped under sticky letter headers. Each row shows the user’s avatar with a presence dot and their name. The list paginates as you scroll, searches the server as you type in its search field, and moves a user who comes online to the top.
CometChatUsers showing an alphabetical list of users with letter headers and presence dots

Where It Fits

CometChatUsers is the directory: the screen a user opens to start a new conversation, or the picker an “add members” flow embeds.
Both toolkits read from the same store, including the letter grouping and the selection, so the SwiftUI and UIKit lists can never disagree about what to show.

Quick Start

That is a working directory: it fetches the first page when it appears, paginates as you scroll and keeps presence live. onItemClick hands you a CometChatSDK.User.The list draws a system navigation bar with a large “Users” title, so it brings its own NavigationStack. If your screen already has one, pass embedsNavigationStack: false. The search field is in the bar and shown by default; pass hideSearchBox: true to leave it out, or hideToolbar: true to hide the bar and the field with it.

What It Looks Like

Rows are 64 pt high with a 40-pt avatar, the name in heading4Medium, and a 14-pt green presence dot at the avatar’s bottom-trailing corner, ringed in the list’s background. The dot shows only for a user who is online and where neither of you has blocked the other. There are no separators unless you ask for them. Users are grouped by the first letter of their name, uppercased; a name that does not start with a letter goes under #. The headers — heading4Medium in the highlight colour, 20 pt in — stay pinned as the list scrolls, and stay on while you search. The groups follow the server’s order rather than re-sorting, so a letter can appear twice: a user who comes online moves to the top and gets their letter’s header there. Loading is a 30-row shimmer. The empty state reads “No Users Available” with “Add contacts to start conversations and see them listed here.”; in UIKit it also shows a person glyph. The error state reads “Oops!” with “Something went wrong. Please try again.” and a Retry button.

Filtering Users

Two builders: one for the list, one used while a search is active.
The list keeps the instance you hand it, so hold it in a @State or a property rather than building a new one in body. The first page builds the request and every later page continues it. Handing the list a different instance after it has loaded applies from the next page on: the rows already loaded stay and nothing is refetched — call store.refreshList() to start over.
With no search builder set, a search writes its keyword into your list builder and it stays there: clearing the field, pull to refresh and a reconnect then load the list filtered by the last keyword. Set a separate search builder to keep your list builder clean.

Filter Recipes

With no builder the list asks for 30 users a page and nothing else. The search runs 300 ms after the last keystroke. It asks the server afresh, replaces the list with the results — still under their letter headers — and pages through them as you scroll. A keystroke while a search is waiting or in flight cancels it, and its answer is dropped. A search that finds nobody shows the empty state; one that fails keeps the rows that were showing. Clearing the field fetches the first page of the list again at once: the rows are cleared and the shimmer shows until it answers.
searchKeyword puts a keyword in the field and searches for it, when the list first appears and whenever the value changes. searchText binds the field’s text if you want to own it.

Actions and Events

Callback Methods

Setting onItemLongClick — as a closure or, in UIKit, a delegate method — replaces the options menu: a long press calls it instead. The swipe actions stay.
onLoad, onEmpty and onError are called when the list changes into that state, not for every page — and once more each time the list appears, with the state it is in. A failure with no rows on screen shows the error state and calls onError. A later page that fails is silent: the rows stay, onError is not called, and scrolling to the end again asks again. Retry asks for the next page.

Global Events

The list consumes two Kit events and emits none. When your own screen blocks or unblocks a user, announce it and the list updates that row in place.
.userUnblocked(user:) is the other.
Everything else the list does is reported through the callbacks above. See Events for the whole bus.

SDK Events (Real-Time, Automatic)

No wiring required — the store listens and the list updates itself.
When the connection is lost, the connection notice shows.
On a reconnect an active search is replaced by the list, and the field keeps its text. Each time the list appears again it loads the next page. Pull to refresh clears the rows and fetches the first page; with rows showing there is no shimmer, so the list is blank until it answers, and a failed refresh shows the error state.

Functionality

hideTitle leaves the bar with an empty title. hideStatusIndicator also takes the presence out of the row’s VoiceOver label.cometChatUsersHidden(_:) hides several parts at once. It takes an option set — .toolbar, .title, .backIcon, .searchBox, .statusIndicator, .stickyHeader, .separator, .loadingState, .emptyState, .errorState — and unions with the hide* arguments: a subtree may hide more, never reveal less.
Users list without letter headers

.stickyHeader

Users list without presence dots

.statusIndicator


Custom View Slots

Every slot is available as an initialiser argument and as a modifier that cascades to every CometChatUsers below it. Supply both and the initialiser argument wins.
Slot closures receive a ChatUser — the row’s value type (id, name, avatarURL, isOnline, isBlockedByMe, hasBlockedMe, isBlocked).
Default Users list with letter headers, avatars, names and presence dots
itemView. Put your own Button in the row, and select through the store.
Users list where itemView replaces the entire row with a compact custom layout
Region slots.
Users list with a custom leading view replacing the default avatar

leadingView

Users list with a custom title view

titleView

Users list with a subtitle line added under each name

subtitleView

Users list with a trailing view added to each row

trailingView

State views. errorView receives a retry closure — call it from your button. It asks for the next page, as the built-in Retry does.
Users list showing a custom loading view

loadingView

Users list showing a custom empty state

emptyView

Users list showing a custom error state with a retry button

errorView

overflowMenu. Adds your own item to the navigation bar’s trailing edge. It is replaced by the tick while a selection is being made.
A custom row view gets no tap, long press, selection, swipe or menu from the Kit — the row handles its own interaction.

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 replaces the list’s (empty) set; addOptions adds to it and is used only when options is not set.

Common Patterns

Open a chat on tap

Friends only, with your own empty state

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.

Preview without credentials


Advanced Methods

Selection

In a selection mode a tap selects or deselects and does nothing else — onItemClick is not called. In .multiple mode a tap toggles the row, with no limit. In .single mode a tap replaces the selection, and a second tap on the selected row keeps it selected: a single selection cannot be emptied by tapping.
Once something is selected the navigation bar shows the count with a cross and a tick. The tick calls onSelection with the selected users 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. The selection lives in the store, so it survives search, paging and refresh — but it is cleared when the list leaves the screen, for example when you push a screen on top of it.

Store Access

UsersStore is the store behind the list. What it exposes:
The list operations — addItem, addItems, removeItem, updateItem, moveItemToTop, clearItems, batch — and addUserToTop never change what the screen is showing. A user added while the empty state is up stays hidden behind it; removing the last row with removeItem leaves a blank list. removeUser is the one that shows the empty state when the last row goes.

Subclassing

CometChatUsers 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, and an app-wide .cometChatTheme(_:) reaches everything a style leaves alone.
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 search field and the selection bar’s items belong to the system’s navigation bar. titleColor, titleFont, the search… and toolbarSeparator… properties and popupMenuStyle have no effect. The selection bar takes discardSelectionIcon, submitSelectionIcon, their tints and selectionCountTextColor / Font; strokeColor, strokeWidth and cornerRadius draw a border and rounding around the list. The stock row has no subtitle, so itemStyle.subtitleColor / subtitleFont style nothing either; a subtitleView styles itself.

Next Steps

Groups

The groups list, built the same way

New Chat

Start conversations from users and groups

Theming

Colour, typography and shape tokens

Component Styling

Style every component