@@ -55,6 +55,8 @@ import TextFormat
5555import AvatarUploadToastScreen
5656import AdsInfoScreen
5757import AdsReportScreen
58+ import SearchBarNode
59+ import ChatListFilterTabContainerNode
5860
5961private final class ContextControllerContentSourceImpl : ContextControllerContentSource {
6062 let controller : ViewController
@@ -768,6 +770,8 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
768770 } )
769771
770772 self . updateNavigationMetadata ( )
773+
774+ self . updateTabBarSearchState ( ViewController . TabBarSearchState ( isActive: false ) , transition: . immediate)
771775 }
772776
773777 required public init ( coder aDecoder: NSCoder ) {
@@ -2838,14 +2842,9 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
28382842 func updateHeaderContent( ) -> ( primaryContent: ChatListHeaderComponent . Content ? , secondaryContent: ChatListHeaderComponent . Content ? ) {
28392843 var primaryContent : ChatListHeaderComponent . Content ?
28402844 if let primaryContext = self . primaryContext {
2841- var backTitle : String ?
2842- if let previousItem = self . previousItem {
2843- switch previousItem {
2844- case let . item( item) :
2845- backTitle = item. title ?? self . presentationData. strings. Common_Back
2846- case . close:
2847- backTitle = self . presentationData. strings. Common_Close
2848- }
2845+ var displayBackButton : Bool = false
2846+ if self . previousItem != nil {
2847+ displayBackButton = true
28492848 }
28502849 var navigationBackTitle : String ?
28512850 if case . chatList( . archive) = self . location {
@@ -2858,8 +2857,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
28582857 chatListTitle: primaryContext. chatListTitle,
28592858 leftButton: primaryContext. leftButton,
28602859 rightButtons: primaryContext. rightButtons,
2861- backTitle: backTitle,
2862- backPressed: backTitle != nil ? { [ weak self] in
2860+ backPressed: displayBackButton ? { [ weak self] in
28632861 guard let self else {
28642862 return
28652863 }
@@ -2876,7 +2874,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
28762874 chatListTitle: secondaryContext. chatListTitle,
28772875 leftButton: secondaryContext. leftButton,
28782876 rightButtons: secondaryContext. rightButtons,
2879- backTitle: nil ,
28802877 backPressed: { [ weak self] in
28812878 guard let self else {
28822879 return
@@ -4638,9 +4635,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
46384635 searchContentNode = navigationBarView. searchContentNode
46394636 }
46404637
4641- if let searchContentNode {
4642- self . activateSearch ( filter: filter, query: query, skipScrolling: false , searchContentNode: searchContentNode)
4643- }
4638+ self . activateSearch ( filter: filter, query: query, skipScrolling: false , searchContentNode: searchContentNode)
46444639 }
46454640
46464641 public func activateSearch( query: String ? = nil ) {
@@ -4654,45 +4649,37 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
46544649 }
46554650
46564651 private var previousSearchToggleTimestamp : Double ?
4657- func activateSearch( filter: ChatListSearchFilter = . chats, query: String ? = nil , skipScrolling: Bool = false , searchContentNode: NavigationBarSearchContentNode ) {
4658- let currentTimestamp = CACurrentMediaTime ( )
4659- if let previousSearchActivationTimestamp = self . previousSearchToggleTimestamp, currentTimestamp < previousSearchActivationTimestamp + 0.6 {
4660- return
4661- }
4662- self . previousSearchToggleTimestamp = currentTimestamp
4663-
4664- if let storyTooltip = self . storyTooltip {
4665- storyTooltip. dismiss ( )
4666- }
4667-
4668- var filter = filter
4669- if case . forum = self . chatListDisplayNode. effectiveContainerNode. location {
4670- filter = . topics
4671- }
4672-
4673- if self . chatListDisplayNode. searchDisplayController == nil {
4674- /*if !skipScrolling, let searchContentNode = self.searchContentNode, searchContentNode.expansionProgress != 1.0 {
4675- self.scrollToTop?()
4676- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.2, execute: { [weak self] in
4677- self?.activateSearch(filter: filter, query: query, skipScrolling: true)
4678- })
4652+ func activateSearch( filter: ChatListSearchFilter = . chats, query: String ? = nil , skipScrolling: Bool = false , searchContentNode: NavigationBarSearchContentNode ? ) {
4653+ Task { @MainActor [ weak self] in
4654+ guard let self else {
4655+ return
4656+ }
4657+
4658+ let currentTimestamp = CACurrentMediaTime ( )
4659+ if let previousSearchActivationTimestamp = self . previousSearchToggleTimestamp, currentTimestamp < previousSearchActivationTimestamp + 0.6 {
46794660 return
4680- }*/
4681- //TODO:scroll to top?
4661+ }
4662+ self . previousSearchToggleTimestamp = currentTimestamp
46824663
4683- let _ = ( combineLatest ( self . chatListDisplayNode. mainContainerNode. currentItemNode. contentsReady |> take ( 1 ) , self . context. account. postbox. tailChatListView ( groupId: . root, count: 16 , summaryComponents: ChatListEntrySummaryComponents ( components: [ : ] ) ) |> take ( 1 ) )
4684- |> deliverOnMainQueue) . startStandalone ( next: { [ weak self] _, chatListView in
4685- Task { @MainActor in
4686- guard let strongSelf = self else {
4687- return
4688- }
4689-
4664+ if let storyTooltip = self . storyTooltip {
4665+ storyTooltip. dismiss ( )
4666+ }
4667+
4668+ var filter = filter
4669+ if case . forum = self . chatListDisplayNode. effectiveContainerNode. location {
4670+ filter = . topics
4671+ }
4672+
4673+ if self . chatListDisplayNode. searchDisplayController == nil {
4674+ let ( _, _) = await combineLatest ( self . chatListDisplayNode. mainContainerNode. currentItemNode. contentsReady |> take ( 1 ) , self . context. account. postbox. tailChatListView ( groupId: . root, count: 16 , summaryComponents: ChatListEntrySummaryComponents ( components: [ : ] ) ) |> take ( 1 ) ) . get ( )
4675+
4676+ do {
46904677 /*if let scrollToTop = strongSelf.scrollToTop {
4691- scrollToTop()
4692- }*/
4678+ scrollToTop()
4679+ }*/
46934680
46944681 let tabsIsEmpty : Bool
4695- if let ( resolvedItems, displayTabsAtBottom, _) = strongSelf . tabContainerData {
4682+ if let ( resolvedItems, displayTabsAtBottom, _) = self . tabContainerData {
46964683 tabsIsEmpty = resolvedItems. count <= 1 || displayTabsAtBottom
46974684 } else {
46984685 tabsIsEmpty = true
@@ -4702,40 +4689,43 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
47024689
47034690 let displaySearchFilters = true
47044691
4705- if let filterContainerNodeAndActivate = await strongSelf . chatListDisplayNode. activateSearch ( placeholderNode: searchContentNode. placeholderNode, displaySearchFilters: displaySearchFilters, hasDownloads: strongSelf . hasDownloads, initialFilter: filter, navigationController: strongSelf . navigationController as? NavigationController ) {
4692+ if let filterContainerNodeAndActivate = await self . chatListDisplayNode. activateSearch ( placeholderNode: searchContentNode? . placeholderNode, displaySearchFilters: displaySearchFilters, hasDownloads: self . hasDownloads, initialFilter: filter, navigationController: self . navigationController as? NavigationController , searchBarIsExternal : true ) {
47064693 let ( filterContainerNode, activate) = filterContainerNodeAndActivate
47074694 if displaySearchFilters {
47084695 let searchTabsNode = SparseNode ( )
4709- strongSelf . searchTabsNode = searchTabsNode
4696+ self . searchTabsNode = searchTabsNode
47104697 searchTabsNode. addSubnode ( filterContainerNode)
47114698 }
47124699
47134700 activate ( filter != . downloads)
47144701
4715- if let searchContentNode = strongSelf . chatListDisplayNode. searchDisplayController? . contentNode as? ChatListSearchContainerNode {
4702+ if let searchContentNode = self . chatListDisplayNode. searchDisplayController? . contentNode as? ChatListSearchContainerNode {
47164703 searchContentNode. search ( filter: filter, query: query)
47174704 }
47184705 }
47194706
47204707 let transition : ContainedViewLayoutTransition = . animated( duration: 0.4 , curve: . spring)
4721- strongSelf. setDisplayNavigationBar ( false , transition: transition)
4722-
4723- ( strongSelf. parent as? TabBarController ) ? . updateIsTabBarHidden ( true , transition: . animated( duration: 0.4 , curve: . spring) )
4724- }
4725- } )
4726-
4727- self . isSearchActive = true
4728- if let navigationController = self . navigationController as? NavigationController {
4729- for controller in navigationController. globalOverlayControllers {
4730- if let controller = controller as? VoiceChatOverlayController {
4731- controller. updateVisibility ( )
4732- break
4708+ self . setDisplayNavigationBar ( false , transition: transition)
4709+ self . updateTabBarSearchState ( ViewController . TabBarSearchState ( isActive: true ) , transition: transition)
4710+ if let searchBarNode = self . currentTabBarSearchNode ? ( ) as? SearchBarNode {
4711+ self . chatListDisplayNode. searchDisplayController? . setSearchBar ( searchBarNode)
4712+ searchBarNode. activate ( )
4713+ }
4714+
4715+ self . isSearchActive = true
4716+ if let navigationController = self . navigationController as? NavigationController {
4717+ for controller in navigationController. globalOverlayControllers {
4718+ if let controller = controller as? VoiceChatOverlayController {
4719+ controller. updateVisibility ( )
4720+ break
4721+ }
4722+ }
47334723 }
47344724 }
4735- }
4736- } else if self . isSearchActive {
4737- if let searchContentNode = self . chatListDisplayNode . searchDisplayController ? . contentNode as? ChatListSearchContainerNode {
4738- searchContentNode . search ( filter : filter , query : query )
4725+ } else if self . isSearchActive {
4726+ if let searchContentNode = self . chatListDisplayNode . searchDisplayController ? . contentNode as? ChatListSearchContainerNode {
4727+ searchContentNode . search ( filter : filter , query : query )
4728+ }
47394729 }
47404730 }
47414731 }
@@ -4766,6 +4756,8 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
47664756 }
47674757 completion = self . chatListDisplayNode. deactivateSearch ( placeholderNode: searchContentNode. placeholderNode, animated: animated)
47684758 searchContentNode. placeholderNode. frame = previousFrame
4759+ } else {
4760+ completion = self . chatListDisplayNode. deactivateSearch ( placeholderNode: nil , animated: animated)
47694761 }
47704762
47714763 self . chatListDisplayNode. tempAllowAvatarExpansion = true
@@ -4780,7 +4772,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
47804772
47814773 completion ? ( )
47824774
4783- ( self . parent as? TabBarController ) ? . updateIsTabBarHidden ( false , transition : . animated ( duration : 0.4 , curve : . spring ) )
4775+ self . updateTabBarSearchState ( ViewController . TabBarSearchState ( isActive : false ) , transition : transition )
47844776
47854777 self . isSearchActive = false
47864778 if let navigationController = self . navigationController as? NavigationController {
@@ -6236,6 +6228,14 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
62366228 strongSelf. context. sharedContext. mainWindow? . presentInGlobalOverlay ( controller)
62376229 } )
62386230 }
6231+
6232+ override public func tabBarActivateSearch( ) {
6233+ self . activateSearch ( )
6234+ }
6235+
6236+ override public func tabBarDeactivateSearch( ) {
6237+ self . deactivateSearch ( animated: true )
6238+ }
62396239
62406240 private var playedSignUpCompletedAnimation = false
62416241 public func playSignUpCompletedAnimation( ) {
0 commit comments