Release Notes
Announcements
Search Entry | Search Results |
![]() | ![]() |
SearchBar serves as the entry point for search functionality. Only the initialization method of the search component is exposed externally; all other logic is encapsulated within SearchBar.Method | Parameter | Description |
init | onTapItem: @escaping (Any) -> Void | Webhook triggered when a search result is clicked, including friend, group, message, and conversation result items. |
SearchBar search results is as follows:onTapItem: @escaping (Any) -> Void webhook. Implement your custom navigation logic in this webhook (for example, navigating to your custom chat interface).// Initialize SearchBarSearchBar(onTapItem: { result inhandleSearchResult(result)})// Handle click events on search results// The onConversationClick event is dispatched to a higher-level component. This is optional and can be adapted based on your project architecture.private func handleSearchResult(_ result: Any) {if let friendInfo = result as? FriendSearchInfo {// Handle selection of a contact from search resultslet conversationID = ChatUtil.getC2CConversationID(friendInfo.userID)var conversation = ConversationInfo(conversationID: conversationID)conversation.type = .c2cconversation.title = friendInfo.friendRemark ?? friendInfo.userInfo.nicknameconversation.avatarURL = friendInfo.userInfo.avatarURL// Dispatch event to the parent component to navigate to the C2C Chat listonConversationClick?(NavigationInfo(conversation: conversation))} else if let groupInfo = result as? GroupSearchInfo {// Handle selection of a group from search resultslet conversationID = ChatUtil.getGroupConversationID(groupInfo.groupID)var conversation = ConversationInfo(conversationID: conversationID)conversation.type = .groupconversation.title = groupInfo.groupNameconversation.avatarURL = groupInfo.groupAvatarURL// Dispatch event to the parent component to navigate to the Group chat listonConversationClick?(NavigationInfo(conversation: conversation))} else if let messageDict = result as? [String: Any],let messageInfo = messageDict["message"] as? MessageInfo,let conversationID = messageDict["conversationID"] as? String{// Handle selection of a message resultvar conversation = ConversationInfo(conversationID: conversationID)if conversationID.hasPrefix("c2c_") {conversation.type = .c2c} else {conversation.type = .group}conversation.title = messageDict["conversationName"] as? Stringconversation.avatarURL = messageDict["conversationAvatar"] as? String// Dispatch event to the parent component to navigate to the conversation and highlight the selected messageonConversationClick?(NavigationInfo(conversation: conversation, locateMessage: messageInfo))} else if let conversationDict = result as? [String: Any],let conversationID = conversationDict["conversationID"] as? String {// Handle selection of a conversation resultvar conversation = ConversationInfo(conversationID: conversationID)if conversationID.hasPrefix("c2c_") {conversation.type = .c2c} else {conversation.type = .group}conversation.title = conversationDict["conversationName"] as? Stringconversation.avatarURL = conversationDict["conversationAvatar"] as? String// Dispatch event to the parent component to navigate to the conversationonConversationClick?(NavigationInfo(conversation: conversation))}}
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback