Skip to main content
The CometChatUsers component displays a searchable list of all available users. It shows user names, avatars, and online/offline status indicators. Users can be filtered, searched, and selected for starting conversations.
CometChatUsers showing a searchable list of users with avatars, names, and online/offline status indicators
FieldValue
ComponentCometChatUsers
PackageCometChatUIKitSwift
InheritsUIViewController

Where It Fits

CometChatUsers displays all available users for starting new conversations. It’s typically used as a standalone screen or within a tab view controller.
CometChatUsers displaying the user list within a navigation controller hierarchy

Minimal Render

CometChatUsers showing the minimal render with default configuration

Filtering

Use UsersRequest.UsersRequestBuilder to filter which users appear in the list. The builder pattern allows chaining multiple filter conditions.

Filter Recipes

RecipeCode
Friends only.friendsOnly(true)
Online users only.set(status: .online)
Search by name.set(searchKeyword: "John")
Filter by role.set(roles: ["admin", "moderator"])
Filter by tags.set(tags: ["premium"])
Hide blocked users.hideBlockedUsers(true)
Limit resultsUsersRequestBuilder(limit: 20)
Specific UIDs.set(UIDs: ["user1", "user2"])

Actions and Events

Callback Props

onItemClick

Fires when a user taps on a user in the list. Use this to start a conversation.

onItemLongClick

Fires when a user long-presses on a user. Use this to show additional options.

onBack

Fires when the back button is pressed.

onSelection

Fires when users are selected in selection mode.

onError

Fires when an error occurs while loading users.

onEmpty

Fires when the user list is empty.

onLoad

Fires when users are successfully loaded. The callback receives a nested array where each inner array represents a section of users (grouped alphabetically).

Actions Reference

MethodDescriptionExample
set(onItemClick:)Triggered when a user is tappedStart conversation
set(onItemLongClick:)Triggered on long pressShow options menu
set(onBack:)Triggered when back button is pressedCustom navigation
set(onSelection:)Triggered in selection modeMulti-select users
set(onError:)Triggered when an error occursShow error alert
set(onEmpty:)Triggered when list is emptyShow empty state
set(onLoad:)Triggered when users loadAnalytics tracking

Global UI Events

EventFires whenPayload
ccUserBlockedA user is blockedUser
ccUserUnblockedA user is unblockedUser

SDK Events (Real-Time, Automatic)

SDK ListenerInternal behavior
onUserOnlineUpdates status indicator to online
onUserOfflineUpdates status indicator to offline

Custom View Slots

SlotSignatureReplaces
listItemView(User) -> UIViewEntire user row
leadingView(User) -> UIViewAvatar / left section
titleView(User?) -> UIViewName / title text
subtitleView(User?) -> UIViewStatus / subtitle text
trailingView(User?) -> UIViewRight side content
emptyStateView() -> UIViewEmpty state display
errorStateView() -> UIViewError state display
loadingStateView() -> UIViewLoading state display

listItemView

Replace the entire user row with a custom design.

leadingView

Customize the leading view (avatar area) of a user cell.
CometChatUsers with custom leadingView showing user avatars with a star badge overlay
You can create a CustomLeadingView as a custom UIView:

titleView

Customize the title view of a user cell.
CometChatUsers with custom titleView showing user names with a green Teacher badge
You can create a CustomTitleView as a custom UIView:

subtitleView

Customize the subtitle area below the user name.
CometChatUsers with custom subtitleView showing last active timestamp below user names
You can create a CustomSubtitleView as a custom UIView:

trailingView

Customize the trailing view (right side) of a user cell.
CometChatUsers with custom trailingView showing a purple PRO badge with star icon
You can create a CustomTrailView as a custom UIView:

loadingStateView

Customize the loading state view displayed while data is being fetched.

errorStateView

Customize the error state view displayed when an error occurs.

emptyStateView

Customize the empty state view displayed when no users are available.

Methods

Swipe Action Methods

set(options:)

Sets custom swipe actions for user list items, replacing the default options. These options appear when the user swipes on a user cell.
ParameterTypeDescription
options((User?) -> [CometChatUserOption])?Closure that returns an array of swipe action options for a user

add(options:)

Adds additional swipe actions to the existing default options.
ParameterTypeDescription
options((User?) -> [CometChatUserOption])?Closure that returns additional swipe action options to append

Data Manipulation Methods

add(user:)

Adds a new user to the user list.
ParameterTypeDescription
userUserThe user to add to the list

update(user:)

Updates an existing user in the list.
ParameterTypeDescription
userUserThe user with updated information

remove(user:)

Removes a user from the list.
ParameterTypeDescription
userUserThe user to remove from the list

getSelectedUsers()

Returns an array of currently selected users when in selection mode.

Custom ListItem

For more complex or unique list items, you can create a custom UIView file named CustomListItem and integrate it into the set(listItemView:) method.
CometChatUsers with custom listItemView showing a simplified user row with avatar and name
Usage:

Styling

Style Hierarchy

  1. Global styles (CometChatUsers.style) apply to all instances
  2. Instance styles override global for specific instances

Global Level Styling

Instance Level Styling

CometChatUsers with custom styling showing modified background colors and text appearance

Key Style Properties

PropertyTypeDefaultDescription
backgroundColorUIColorCometChatTheme.backgroundColor01Background color
titleColorUIColorCometChatTheme.textColorPrimaryNavigation title color
titleFontUIFontCometChatTypography.Heading4.mediumNavigation title font
listItemTitleTextColorUIColorCometChatTheme.textColorPrimaryUser name color
listItemTitleFontUIFontCometChatTypography.Heading4.mediumUser name font
listItemSubTitleTextColorUIColorCometChatTheme.textColorSecondaryStatus text color
listItemSubTitleFontUIFontCometChatTypography.Body.regularStatus text font
listItemBackgroundUIColor.clearList item background
searchBarBackgroundColorUIColor?nilSearch bar background
searchBarTextColorUIColor?nilSearch bar text color
headerTitleColorUIColorCometChatTheme.textColorHighlightSection header color
headerTitleFontUIFontCometChatTypography.Heading4.mediumSection header font

Customization Matrix

What to changeWhereProperty/APIExample
Background colorStylebackgroundColorUIColor.systemBackground
Title appearanceStyletitleColor, titleFontCustom colors and fonts
List item lookStylelistItemBackgroundUIColor.white
Avatar appearanceStyleavatarStyleAvatarStyle() with custom radius
Search barStylesearchBarBackgroundColorCustom background
Hide searchPropertyhideSearchusers.hideSearch = true
Hide statusPropertyhideUserStatususers.hideUserStatus = true
Custom rowView Slotset(listItemView:)See Custom View Slots

Props

All props are optional. Sorted alphabetically.

avatarStyle

Customizes the appearance of avatars in user list items.
TypeAvatarStyle
DefaultAvatarStyle()

hideBackButton

Hides the back button in the navigation bar.
TypeBool
Defaultfalse

hideErrorView

Hides the error state view.
TypeBool
Defaultfalse

hideLoadingState

Hides the loading state indicator.
TypeBool
Defaultfalse

hideNavigationBar

Hides the entire navigation bar.
TypeBool
Defaultfalse

hideSearch

Hides the search bar.
TypeBool
Defaultfalse

hideSectionHeader

Hides the alphabetical section headers.
TypeBool
Defaultfalse

hideUserStatus

Hides online/offline status indicators.
TypeBool
Defaultfalse

onSelectedItemProceed

Callback triggered when the user confirms their selection in selection mode. Use this to handle the selected users.
Type(([User]) -> Void)?
Defaultnil

searchRequestBuilder

Custom request builder for search functionality.
TypeUsersRequest.UsersRequestBuilder?
Defaultnil

selectedCellCount

Returns the count of currently selected users in selection mode.
TypeInt
Default0

selectionLimit

Sets the maximum number of users that can be selected in selection mode. When the limit is reached, further selections are disabled.
TypeInt
Default0 (unlimited)

selectionMode

Sets the selection mode for multi-select functionality.
TypeSelectionMode
Default.none

statusIndicatorStyle

Customizes the appearance of online/offline status indicators.
TypeStatusIndicatorStyle
DefaultStatusIndicatorStyle()

usersRequestBuilder

Custom request builder for filtering users.
TypeUsersRequest.UsersRequestBuilder?
Defaultnil

Events

EventPayloadFires when
ccUserBlockedUserA user is blocked
ccUserUnblockedUserA user is unblocked

Common Patterns

Friends-only list

Online users only

Custom empty state with CTA

Hide all chrome — minimal list

Multi-select users