Skip to content

Commit 5e26b24

Browse files
author
Isaac
committed
[WIP] Tab bar and search
1 parent dd8040f commit 5e26b24

File tree

33 files changed

+1468
-810
lines changed

33 files changed

+1468
-810
lines changed

Telegram/BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ load("@build_bazel_rules_apple//apple:ios.bzl",
88
"ios_application",
99
"ios_extension",
1010
"ios_framework",
11-
"ios_unit_test",
12-
"ios_ui_test",
1311
)
1412

1513
load("@build_bazel_rules_apple//apple:resources.bzl",
@@ -22,7 +20,6 @@ load("@build_bazel_rules_swift//swift:swift.bzl",
2220

2321
load(
2422
"@rules_xcodeproj//xcodeproj:defs.bzl",
25-
"top_level_target",
2623
"top_level_targets",
2724
"xcodeproj",
2825
"xcode_provisioning_profile",

submodules/CallListUI/Sources/CallListController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ public final class CallListController: TelegramBaseController {
155155
if case .navigation = self.mode {
156156
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Back, style: .plain, target: nil, action: nil)
157157
}
158+
159+
self.updateTabBarSearchState(ViewController.TabBarSearchState(isActive: false), transition: .immediate)
158160
}
159161

160162
required public init(coder aDecoder: NSCoder) {

submodules/ChatListUI/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ swift_library(
118118
"//submodules/TelegramUI/Components/ButtonComponent",
119119
"//submodules/TelegramUI/Components/AnimatedTextComponent",
120120
"//submodules/TelegramUI/Components/EdgeEffect",
121+
"//submodules/TelegramUI/Components/ChatList/ChatListFilterTabContainerNode",
121122
],
122123
visibility = [
123124
"//visibility:public",

submodules/ChatListUI/Sources/ChatListController.swift

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import TextFormat
5555
import AvatarUploadToastScreen
5656
import AdsInfoScreen
5757
import AdsReportScreen
58+
import SearchBarNode
59+
import ChatListFilterTabContainerNode
5860

5961
private 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() {

submodules/ChatListUI/Sources/ChatListControllerNode.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import ChatListHeaderComponent
2222
import StoryPeerListComponent
2323
import TelegramNotices
2424
import EdgeEffect
25+
import ChatListFilterTabContainerNode
2526

2627
public enum ChatListContainerNodeFilter: Equatable {
2728
case all
@@ -1382,8 +1383,8 @@ final class ChatListControllerNode: ASDisplayNode, ASGestureRecognizerDelegate {
13821383
strings: self.presentationData.strings,
13831384
statusBarHeight: layout.statusBarHeight ?? 0.0,
13841385
sideInset: layout.safeInsets.left,
1386+
search: nil, //ChatListNavigationBar.Search(isEnabled: true),
13851387
isSearchActive: self.isSearchDisplayControllerActive,
1386-
isSearchEnabled: true,
13871388
primaryContent: headerContent?.primaryContent,
13881389
secondaryContent: headerContent?.secondaryContent,
13891390
secondaryTransition: self.inlineStackContainerTransitionFraction,
@@ -1540,7 +1541,8 @@ final class ChatListControllerNode: ASDisplayNode, ASGestureRecognizerDelegate {
15401541
var storiesInset = storiesInset
15411542

15421543
let navigationBarLayout = self.updateNavigationBar(layout: layout, deferScrollApplication: true, transition: ComponentTransition(transition))
1543-
self.mainContainerNode.initialScrollingOffset = ChatListNavigationBar.searchScrollHeight + navigationBarLayout.storiesInset
1544+
//self.mainContainerNode.initialScrollingOffset = ChatListNavigationBar.searchScrollHeight + navigationBarLayout.storiesInset
1545+
self.mainContainerNode.initialScrollingOffset = navigationBarLayout.storiesInset
15441546

15451547
navigationBarHeight = navigationBarLayout.navigationHeight
15461548
visualNavigationHeight = navigationBarLayout.navigationHeight
@@ -1666,7 +1668,7 @@ final class ChatListControllerNode: ASDisplayNode, ASGestureRecognizerDelegate {
16661668
}
16671669

16681670
@MainActor
1669-
func activateSearch(placeholderNode: SearchBarPlaceholderNode, displaySearchFilters: Bool, hasDownloads: Bool, initialFilter: ChatListSearchFilter, navigationController: NavigationController?) async -> (ASDisplayNode, (Bool) -> Void)? {
1671+
func activateSearch(placeholderNode: SearchBarPlaceholderNode?, displaySearchFilters: Bool, hasDownloads: Bool, initialFilter: ChatListSearchFilter, navigationController: NavigationController?, searchBarIsExternal: Bool) async -> (ASDisplayNode, (Bool) -> Void)? {
16701672
guard let (containerLayout, _, _, cleanNavigationBarHeight, _) = self.containerLayout, self.searchDisplayController == nil else {
16711673
return nil
16721674
}
@@ -1712,7 +1714,7 @@ final class ChatListControllerNode: ASDisplayNode, ASGestureRecognizerDelegate {
17121714
if let requestDeactivateSearch = self?.requestDeactivateSearch {
17131715
requestDeactivateSearch()
17141716
}
1715-
})
1717+
}, searchBarIsExternal: searchBarIsExternal)
17161718
self.mainContainerNode.accessibilityElementsHidden = true
17171719
self.inlineStackContainerNode?.accessibilityElementsHidden = true
17181720

@@ -1742,15 +1744,16 @@ final class ChatListControllerNode: ASDisplayNode, ASGestureRecognizerDelegate {
17421744
})
17431745
}
17441746

1745-
func deactivateSearch(placeholderNode: SearchBarPlaceholderNode, animated: Bool) -> (() -> Void)? {
1747+
func deactivateSearch(placeholderNode: SearchBarPlaceholderNode?, animated: Bool) -> (() -> Void)? {
17461748
if let searchDisplayController = self.searchDisplayController {
17471749
self.isSearchDisplayControllerActive = false
17481750
self.searchDisplayController = nil
17491751
self.mainContainerNode.accessibilityElementsHidden = false
17501752
self.inlineStackContainerNode?.accessibilityElementsHidden = false
17511753

17521754
return { [weak self, weak placeholderNode] in
1753-
if let strongSelf = self, let placeholderNode, let (layout, _, _, cleanNavigationBarHeight, _) = strongSelf.containerLayout {
1755+
if let strongSelf = self, let (layout, _, _, cleanNavigationBarHeight, _) = strongSelf.containerLayout {
1756+
let placeholderNode = placeholderNode
17541757
searchDisplayController.deactivate(placeholder: placeholderNode, animated: animated)
17551758

17561759
searchDisplayController.containerLayoutUpdated(layout, navigationBarHeight: cleanNavigationBarHeight, transition: .animated(duration: 0.4, curve: .spring))

0 commit comments

Comments
 (0)