Search Conversation Screen
Overview
The LMChatSearchConversationListViewController
displays and manages search results for conversations and chatrooms. It provides a search bar, paginated table view, and analytics hooks for search actions.
File Location:
LMChatSearchConversationListViewController.swift
Functionality
Protocols Implemented
UITableViewDataSource
/UITableViewDelegate
: Manages table view data and interactions.UISearchBarDelegate
: Handles search bar text changes and search logic.LMChatSearchConversationListViewProtocol
: Defines the interface for updating the conversation search list UI. Implementers of this protocol are typically view controllers that display the search results.updateSearchList(with data: [LMChatSearchConversationListViewController.ContentModel])
: Updates the search list displayed in the view with an array of sectioned search results.showHideFooterLoader(isShow: Bool)
: Shows or hides a footer loader in the view for pagination.
UI Components
tableView
: A grouped-styleUITableView
for displaying search results with custom cells.searchController
: AUISearchController
for managing the search bar and its interactions.LMChatSearchConversationMessageCell
: Custom cell for displaying matched conversation messages.
Properties
searchResults
([ContentModel]
): Sectioned search results, each with an optional title and a list of items.viewmodel
(LMChatSearchConversationListViewModel?
): Manages data fetching, search operations, and pagination.
Methods
searchBar(_:textDidChange:)
: Debounces typing, triggers search, and updates results.searchBarCancelButtonClicked(_:)
: Resets the search and tracks analytics for cancellation.resetSearchData()
: Clears results and reloads the table.updateSearchList(with:)
: Refreshes the table view with new data or shows a "no result" view.showHideFooterLoader(isShow:)
: Toggles a footer loader for pagination.
Customization
CustomSearchConversationListViewController.swift
class CustomSearchConversationListViewController: LMChatSearchConversationListViewController {
override func setupViews() {
super.setupViews()
// Customize table or other UI elements here
}
override func setupAppearance() {
super.setupAppearance()
// Adjust background colors, text attributes, etc.
view.backgroundColor = .lightGray
}
}
AppDelegate.swift
func application(
_ application: UIApplication,
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
// Replace the default with your custom class
LMCoreComponents.shared.searchConversationListViewController = CustomSearchConversationListViewController.self
// ...
return true
}
Models
ContentModel
A data model representing a section in the search result list.
VARIABLE | TYPE | DESCRIPTION | Optional |
---|---|---|---|
title | String | An optional title for this section | ✔️ |
data | [LMChatSearchCellDataProtocol] | A list of items to display in this section |
Each item in the data
array represents a result conforming to LMChatSearchCellDataProtocol
(such as a chatroom or conversation message). These items are then rendered in the table view cells.