From ecd8083ebeea8a1a9e7c0fbbcc39b57458d6f6e1 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Tue, 30 Jan 2024 11:04:19 +1100 Subject: [PATCH] WIP: refactor global search screen into SwiftUI --- Session.xcodeproj/project.pbxproj | 4 ++ .../GlobalSearch/GlobalSearchScreen.swift | 57 +++++++++++++++++++ Session/Home/HomeVC.swift | 3 +- .../Components/SwiftUI/SessionSearchBar.swift | 12 +++- 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 Session/Home/GlobalSearch/GlobalSearchScreen.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 8236eae14..9902ea7ae 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -168,6 +168,7 @@ 7BFD1A8C2747150E00FB91B9 /* TurnServerInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BFD1A8B2747150E00FB91B9 /* TurnServerInfo.swift */; }; 7BFD1A972747689000FB91B9 /* Session-Turn-Server in Resources */ = {isa = PBXBuildFile; fileRef = 7BFD1A962747689000FB91B9 /* Session-Turn-Server */; }; 942C9CA22B67769000B5153A /* SessionSearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 942C9CA12B67769000B5153A /* SessionSearchBar.swift */; }; + 942C9CA42B6868B800B5153A /* GlobalSearchScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 942C9CA32B6868B800B5153A /* GlobalSearchScreen.swift */; }; 946B34472B5DF0B7004CB4A3 /* QRCodeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946B34462B5DF0B7004CB4A3 /* QRCodeScreen.swift */; }; 946B34492B5E04BB004CB4A3 /* CustomTopTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946B34482B5E04BB004CB4A3 /* CustomTopTabBar.swift */; }; 946B344B2B5E08F3004CB4A3 /* ScanQRCodeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946B344A2B5E08F3004CB4A3 /* ScanQRCodeScreen.swift */; }; @@ -1308,6 +1309,7 @@ 92E8569C96285EE3CDB5960D /* Pods_GlobalDependencies_FrameworkAndExtensionDependencies_ExtendedDependencies_SignalUtilitiesKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GlobalDependencies_FrameworkAndExtensionDependencies_ExtendedDependencies_SignalUtilitiesKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 93359C81CF2660040B7CD106 /* Pods_GlobalDependencies_FrameworkAndExtensionDependencies_ExtendedDependencies_SessionUtilitiesKit_SessionUtilitiesKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GlobalDependencies_FrameworkAndExtensionDependencies_ExtendedDependencies_SessionUtilitiesKit_SessionUtilitiesKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 942C9CA12B67769000B5153A /* SessionSearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionSearchBar.swift; sourceTree = ""; }; + 942C9CA32B6868B800B5153A /* GlobalSearchScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalSearchScreen.swift; sourceTree = ""; }; 946B34462B5DF0B7004CB4A3 /* QRCodeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeScreen.swift; sourceTree = ""; }; 946B34482B5E04BB004CB4A3 /* CustomTopTabBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTopTabBar.swift; sourceTree = ""; }; 946B344A2B5E08F3004CB4A3 /* ScanQRCodeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanQRCodeScreen.swift; sourceTree = ""; }; @@ -2463,6 +2465,7 @@ children = ( 7BAF54CC27ACCEEC003D12F8 /* GlobalSearchViewController.swift */, 7BAF54CD27ACCEEC003D12F8 /* EmptySearchResultCell.swift */, + 942C9CA32B6868B800B5153A /* GlobalSearchScreen.swift */, ); path = GlobalSearch; sourceTree = ""; @@ -6259,6 +6262,7 @@ B877E24226CA12910007970A /* CallVC.swift in Sources */, FDC498B92AC15FE300EDD897 /* AppNotificationAction.swift in Sources */, 7BA6890D27325CCC00EFC32F /* SessionCallManager+CXCallController.swift in Sources */, + 942C9CA42B6868B800B5153A /* GlobalSearchScreen.swift in Sources */, C374EEEB25DA3CA70073A857 /* ConversationTitleView.swift in Sources */, FD716E7128505E5200C96BF4 /* MessageRequestsCell.swift in Sources */, FDF848F329413DB0007DCAE5 /* ImagePickerHandler.swift in Sources */, diff --git a/Session/Home/GlobalSearch/GlobalSearchScreen.swift b/Session/Home/GlobalSearch/GlobalSearchScreen.swift new file mode 100644 index 000000000..d81d18a29 --- /dev/null +++ b/Session/Home/GlobalSearch/GlobalSearchScreen.swift @@ -0,0 +1,57 @@ +// Copyright © 2024 Rangeproof Pty Ltd. All rights reserved. + +import SwiftUI +import GRDB +import DifferenceKit +import SessionUIKit +import SessionMessagingKit +import SessionUtilitiesKit +import SignalUtilitiesKit +import SignalCoreKit + +struct GlobalSearchScreen: View { + fileprivate typealias SectionModel = ArraySection + + enum SearchSection: Int, Differentiable { + case noResults + case contactsAndGroups + case messages + } + + @EnvironmentObject var host: HostWrapper + + @State var searchText: String = "" + @State private var searchResultSet: [SectionModel] = [] + + var body: some View { + ZStack(alignment: .topLeading) { + ScrollView(.vertical, showsIndicators: false) { + VStack( + alignment: .leading, + spacing: Values.smallSpacing + ) { + SessionSearchBar( + searchText: $searchText.onChange{ updatedSearchText in + onSearchTextChange(updatedSearchText: updatedSearchText) + }, + cancelAction: { + self.host.controller?.navigationController?.popViewController(animated: true) + } + ) + + + } + } + } + .backgroundColor(themeColor: .backgroundPrimary) + } + + func onSearchTextChange(updatedSearchText: String) { + guard updatedSearchText != searchText else { return } + + } +} + +#Preview { + GlobalSearchScreen() +} diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift index faecee9a5..26f9bdf35 100644 --- a/Session/Home/HomeVC.swift +++ b/Session/Home/HomeVC.swift @@ -863,7 +863,8 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData if let presentedVC = self.presentedViewController { presentedVC.dismiss(animated: false, completion: nil) } - let searchController = GlobalSearchViewController() +// let searchController = GlobalSearchViewController() + let searchController = SessionHostingViewController(rootView: GlobalSearchScreen()) self.navigationController?.setViewControllers([ self, searchController ], animated: true) } diff --git a/SessionUIKit/Components/SwiftUI/SessionSearchBar.swift b/SessionUIKit/Components/SwiftUI/SessionSearchBar.swift index f43c65768..5f51360c6 100644 --- a/SessionUIKit/Components/SwiftUI/SessionSearchBar.swift +++ b/SessionUIKit/Components/SwiftUI/SessionSearchBar.swift @@ -2,14 +2,20 @@ import SwiftUI -struct SessionSearchBar: View { +public struct SessionSearchBar: View { @Binding var searchText: String - let cancelAction: () -> () + let cancelAction: () -> Void let height: CGFloat = 40 let cornerRadius: CGFloat = 7 - var body: some View { + + public init(searchText: Binding, cancelAction: @escaping () -> Void) { + self._searchText = searchText + self.cancelAction = cancelAction + } + + public var body: some View { HStack( alignment: .center, spacing: 0