Custom dismiss for inline chat search

This commit is contained in:
Isaac 2024-02-02 14:54:16 +01:00
parent 47660fcf2b
commit 561c4287b5
4 changed files with 33 additions and 8 deletions

View File

@ -938,6 +938,7 @@ public protocol ChatController: ViewController {
var purposefulAction: (() -> Void)? { get set }
var stateUpdated: ((ContainedViewLayoutTransition) -> Void)? { get set }
var customDismissSearch: (() -> Void)? { get set }
var selectedMessageIds: Set<EngineMessage.Id>? { get }
var presentationInterfaceStateSignal: Signal<Any, NoError> { get }

View File

@ -409,6 +409,17 @@ public final class PeerInfoChatListPaneNode: ASDisplayNode, PeerInfoPaneNode, UI
return
}
chatController.customDismissSearch = { [weak self] in
guard let self else {
return
}
if self.searchNavigationContentNode !== nil {
self.searchNavigationContentNode = nil
self.externalDataUpdated?(.animated(duration: 0.4, curve: .spring))
}
self.removeChatController()
}
chatController.stateUpdated = { [weak self] transition in
guard let self, let chatController = self.chatController else {
return

View File

@ -517,6 +517,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
public var customNavigationPanelNode: ChatControllerCustomNavigationPanelNode?
public var stateUpdated: ((ContainedViewLayoutTransition) -> Void)?
public var customDismissSearch: (() -> Void)?
public override var customData: Any? {
return self.chatLocation
}
@ -9091,13 +9093,20 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
strongSelf.updateItemNodesSearchTextHighlightStates()
})
}, dismissMessageSearch: { [weak self] in
if let strongSelf = self {
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { current in
return current.updatedSearch(nil).updatedHistoryFilter(nil)
})
strongSelf.updateItemNodesSearchTextHighlightStates()
strongSelf.searchResultsController = nil
guard let self else {
return
}
if let customDismissSearch = self.customDismissSearch {
customDismissSearch()
return
}
self.updateChatPresentationInterfaceState(animated: true, interactive: true, { current in
return current.updatedSearch(nil).updatedHistoryFilter(nil)
})
self.updateItemNodesSearchTextHighlightStates()
self.searchResultsController = nil
}, updateMessageSearch: { [weak self] query in
if let strongSelf = self {
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { current in

View File

@ -2475,8 +2475,12 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
mappedContents = .search(query: self.chatPresentationInterfaceState.search?.query ?? "", includeSavedPeers: self.alwaysShowSearchResultsAsList)
} else if let historyFilter = self.chatPresentationInterfaceState.historyFilter {
mappedContents = .tag(historyFilter.customTag)
} else if let search = self.chatPresentationInterfaceState.search, !search.query.isEmpty, self.alwaysShowSearchResultsAsList {
mappedContents = .search(query: search.query, includeSavedPeers: self.alwaysShowSearchResultsAsList)
} else if let search = self.chatPresentationInterfaceState.search, self.alwaysShowSearchResultsAsList {
if !search.query.isEmpty {
mappedContents = .search(query: search.query, includeSavedPeers: self.alwaysShowSearchResultsAsList)
} else {
mappedContents = .empty
}
} else if case .peer(self.context.account.peerId) = self.chatPresentationInterfaceState.chatLocation {
mappedContents = .tag(MemoryBuffer())
} else {