Skip to main content
Version: v4

Contacts

CometChatContacts is a UIViewController specifically designed to facilitate the display and management of users and groups within chat applications. It streamlines the process of showcasing all app users and available chat groups in a user-friendly interface, making it easier for users to connect and communicate effectively. Additionally, the view controller includes a UISegmentedControl to switch between the users and groups list, enhancing navigation and usability.

Key Features:

  1. User List View: CometChatContacts presents a comprehensive list of all registered users within the application. This list allows users to quickly find and select specific individuals they wish to interact with.
  2. Group List View: The component also offers a dedicated view to showcase all the available chat groups. This simplifies the process of joining or creating new group conversations.
  3. Smart Search Functionality: Users can utilize the powerful search feature to quickly locate specific users or groups by typing names or keywords. This ensures seamless navigation, even in applications with a large user base.
  4. Selection Mode: CometChatContacts supports a selection mode, enabling users to pick multiple contacts or groups simultaneously. This feature proves useful for creating group chats or forwarding messages to multiple recipients.
  5. Customizable Tab Layout: Developers can easily customize the appearance of the tabs, including text colors, indicator color, and background, to match the app's branding and aesthetics.
  6. Selection Limit Control: Developers have the flexibility to set a selection limit, restricting the number of contacts or groups a user can select during the selection mode. This helps maintain messaging policies and optimize user experience.
  7. User-Friendly Close Button: The component provides a convenient close button feature, allowing users to exit the Contacts view and return to their previous screen or chat interface effortlessly.

How to integrate CometChatContacts

CometChatContacts can launched on to a new screen using the following code snippet.

self.present(UINavigationController(rootViewController: CometChatContacts()), animated: true)

Methods

MethodsParametersDescription
titleStringSets the title that will be displayed at the top of the CometChatContacts view. This method allows you to customize the title to provide relevant information or context to the users.
usersTabTitleStringusersTabTitle is used to set the users tab title for the CometChatContacts Component
groupsTabTitleStringgroupsTabTitle is used to set the groups tab title for the CometChatContacts Component.
usersConfigurationUsersConfigurationusersConfiguration is used to set the configurations for the CometChatUsers Component embedded in CometChatContacts Component.
groupsConfigurationGroupsConfigurationgroupsConfiguration is used to set the configurations for the CometChatGroups Component embedded in CometChatContacts Component.
onItemTap(_ controller: UIViewController?, user: User?, group: Group?) -> VoidonItemTap is used to set the action to be performed when a user or group is tapped.
closeIconUIImagecloseIcon is used to set the close icon.
onClose() -> VoidonClose is used to set the action to be performed when close icon is tapped.
submitIconUIImagesubmitIcon is used to set the submit icon
onSubmitIconTap(_ selectedUsers: [User]? , _ selectedGroups: [Group]?) -> VoidonSubmitIconTap is used to set the action to be performed when submit icon is tapped
hideSubmitButtonBoolhideSubmitButton is used to hide the submit button in CometChatContacts Component.
selectionLimitIntselectionLimit is used to set the selection limit for the CometChatUsers and CometChatGroups subviews embedded inside CometChatContacts.
selectionModeSelectionModeselectionMode is used to set the selection mode for the CometChatUsers and CometChatGroups subviews embedded inside CometChatContacts.
contactsStyleContactsStylethe property contactsStyle is used to set the style for the CometChatContacts Component.
tabVisibilityTabVisibilitythe property tabVisibility is used to set the tab visibility for the CometChatContacts Component. Default value is usersAndGroups.

ContactsStyle

This property is used to customize the appearance of the CometChatContacts component.

MethodsParameterDescription
titleTextColorUIColorused to set the text color of the title
titleTextFontUIFontused to set the text font of the title
tabTitleTextColorUIColoris used to set the tab title text color
tabTitleTextFontUIFontused to set the tab title text font
tabWidthCGFloatused to set the tab width
tabHeightCGFloatused to set the tab height
activeTabTitleTextColorUIColorused to set the active tab title text color
activeTabBackgroundUIColorused to set the active tab background color
closeIconTintUIColorused to set the close icon tint color
selectionIconTintUIColorused to set the selection icon tint color
errorStateTextColorUIColorused to set the error state text color
errorStateTextFontUIFontused to set the error state text font
submitButtonBackgroundUIColorused to set the submit button background color
submitButtonTextColorUIColorused to set the submit button text color
submitButtonTextFontUIFontused to set the submit button text font
tableViewStyleUITableView.Styleused to set the tableView style, default value is insetGrouped
let contacts = CometChatContacts()
let contactsStyle = ContactsStyle()
contactsStyle
.set(activeTabBackground: UIColor(red: 0.00, green: 0.48, blue: 1.00, alpha: 1.00))
.set(activeTabTitleTextColor: .white)
.set(background: .white)
.set(borderColor: UIColor(red: 0.78, green: 0.78, blue: 0.80, alpha: 1.00))
.set(borderWidth: 1)
.set(closeIconTint: UIColor(red: 0.00, green: 0.48, blue: 1.00, alpha: 1.00))
.set(errorStateTextColor: UIColor(red: 0.00, green: 0.48, blue: 1.00, alpha: 1.00))
.set(errorStateTextFont: UIFont.systemFont(ofSize: 16))
.set(selectionIconTint: UIColor(red: 0.00, green: 0.48, blue: 1.00, alpha: 1.00))
.set(submitButtonTextColor: .blue)
.set(submitButtonBackground: .white)
.set(submitButtonTextFont: UIFont.systemFont(ofSize: 16))

contacts.setContactsStyle(contactsStyle: contactsStyle)

let naviVC = UINavigationController(rootViewController: contacts)

self.present(naviVC, animated: true)
tip

If you are already using a navigation controller, you can use the pushViewController function instead of presenting the view controller.