From ea4c003741634c701b27acf57d7d3238e5c9955b Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Mon, 15 Sep 2025 10:33:11 +0200 Subject: [PATCH] fixed search --- ElementX.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 6 +- ElementX/Sources/Other/SwiftUI/Search.swift | 59 +++++++++++++------ project.yml | 2 +- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index fa6f3a37f..7e5f1f231 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -9491,7 +9491,7 @@ repositoryURL = "https://github.com/element-hq/compound-ios"; requirement = { kind = revision; - revision = 07563f32203a0a8c3a660cc9fc7cd59cdebcc34f; + revision = 92f99140d925e77f01f5ef72c1aeffe0b0e3d96a; }; }; F76A08D0EA29A07A54F4EB4D /* XCRemoteSwiftPackageReference "swift-collections" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 940d5b02b..bced388ef 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -15,7 +15,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/element-hq/compound-ios", "state" : { - "revision" : "07563f32203a0a8c3a660cc9fc7cd59cdebcc34f" + "revision" : "92f99140d925e77f01f5ef72c1aeffe0b0e3d96a" } }, { @@ -311,8 +311,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/siteline/SwiftUI-Introspect", "state" : { - "revision" : "807f73ce09a9b9723f12385e592b4e0aaebd3336", - "version" : "1.3.0" + "revision" : "712db7f70540eb0d09d72a7a34c6fa6092c9a142", + "version" : "26.0.0-rc.1" } }, { diff --git a/ElementX/Sources/Other/SwiftUI/Search.swift b/ElementX/Sources/Other/SwiftUI/Search.swift index 9d9fa0de9..60c5a62ef 100644 --- a/ElementX/Sources/Other/SwiftUI/Search.swift +++ b/ElementX/Sources/Other/SwiftUI/Search.swift @@ -7,7 +7,7 @@ import GameController import SwiftUI -import SwiftUIIntrospect +@_spi(Advanced) import SwiftUIIntrospect // MARK: - Search Controller Extensions @@ -52,24 +52,49 @@ private struct SearchControllerModifier: ViewModifier { /// is `false`, checking if this value is `false` is pretty much meaningless. @State private var isSearching = false + @ViewBuilder func body(content: Content) -> some View { - content - .interactiveDismissDisabled(!searchQuery.isEmpty && disablesInteractiveDismiss) - .background { - SearchController(searchQuery: $searchQuery, - placeholder: placeholder, - hidesNavigationBar: hidesNavigationBar, - showsCancelButton: showsCancelButton, - hidesSearchBarWhenScrolling: false, - accessibilityFocusOnStart: accessibilityFocusOnStart, - isSearching: $isSearching) - } - .onDisappear { - // Dismiss search when the view disappears to tidy up appearance when popping back to the view. - if isSearching { - isSearching = false + let text: Text? = if let placeholder { + Text(placeholder) + } else { + nil + } + + if #available(iOS 26, *) { + content + .searchable(text: $searchQuery, placement: .navigationBarDrawer(displayMode: .always), prompt: text) + .interactiveDismissDisabled(!searchQuery.isEmpty && disablesInteractiveDismiss) + .introspect(.navigationStack, on: .supportedVersions, scope: .ancestor) { navigationController in + // Uses the navigation stack as .searchField is unreliable when pushing the second search bar, during the create rooms flow. + guard let searchController = navigationController.navigationBar.topItem?.searchController else { return } + searchController.automaticallyShowsCancelButton = showsCancelButton + searchController.hidesNavigationBarDuringPresentation = hidesNavigationBar } - } + .onDisappear { + // Dismiss search when the view disappears to tidy up appearance when popping back to the view. + if isSearching { + isSearching = false + } + } + } else { + content + .interactiveDismissDisabled(!searchQuery.isEmpty && disablesInteractiveDismiss) + .background { + SearchController(searchQuery: $searchQuery, + placeholder: placeholder, + hidesNavigationBar: hidesNavigationBar, + showsCancelButton: showsCancelButton, + hidesSearchBarWhenScrolling: false, + accessibilityFocusOnStart: accessibilityFocusOnStart, + isSearching: $isSearching) + } + .onDisappear { + // Dismiss search when the view disappears to tidy up appearance when popping back to the view. + if isSearching { + isSearching = false + } + } + } } } diff --git a/project.yml b/project.yml index d148d6e73..c234cfb59 100644 --- a/project.yml +++ b/project.yml @@ -72,7 +72,7 @@ packages: # path: ../matrix-rust-sdk Compound: url: https://github.com/element-hq/compound-ios - revision: 07563f32203a0a8c3a660cc9fc7cd59cdebcc34f + revision: 92f99140d925e77f01f5ef72c1aeffe0b0e3d96a # path: ../compound-ios AnalyticsEvents: url: https://github.com/matrix-org/matrix-analytics-events