Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for SearchField (.searchable) in NavigationSplitView #423

gojosh started this conversation in Ideas
Discussion options

Proposed new ViewType, SearchFieldSplitView, for support of SearchField (.searchable) in NavigationSplitView:

import SwiftUI
@_spi(Advanced) @_spi(Internals) import SwiftUIIntrospect
/// An abstract representation of the search field displayed via the `.searchable` modifier in SwiftUI.
///
/// ### iOS
///
/// ```swift
/// struct ContentView: View {
/// @State var searchTerm = ""
///
/// var body: some View {
/// NavigationSplitView {
/// Text("Sidebar")
/// .searchable(text: $searchTerm)
/// } detail: {
/// Text("Detail")
/// }
/// .introspect(.searchFieldSplitView, on: .iOS(.v15, .v16, .v17)) {
/// print(type(of: 0ドル)) // UISearchBar
/// }
/// }
/// }
/// ```
///
/// ### tvOS
///
/// ```swift
/// struct ContentView: View {
/// @State var searchTerm = ""
///
/// var body: some View {
/// NavigationSplitView {
/// Text("Sidebar")
/// .searchable(text: $searchTerm)
/// } detail: {
/// Text("Detail")
/// }
/// .introspect(.searchFieldSplitView, on: .tvOS(.v15, .v16, .v17)) {
/// print(type(of: 0ドル)) // UISearchBar
/// }
/// }
/// }
/// ```
///
/// ### macOS
///
/// Not available.
///
/// ### visionOS
///
/// ```swift
/// struct ContentView: View {
/// @State var searchTerm = ""
///
/// var body: some View {
/// NavigationSplitView {
/// Text("Sidebar")
/// .searchable(text: $searchTerm)
/// } detail: {
/// Text("Detail")
/// }
/// .introspect(.searchFieldSplitView, on: .visionOS(.v1)) {
/// print(type(of: 0ドル)) // UISearchBar
/// }
/// }
/// }
/// ```
#if !os(watchOS)
public struct SearchFieldSplitViewType: IntrospectableViewType {}
extension IntrospectableViewType where Self == SearchFieldSplitViewType {
 public static var searchFieldSplitView: Self { .init() }
}
#if canImport(UIKit)
extension iOSViewVersion<SearchFieldSplitViewType, UISearchBar> {
 @available(*, unavailable, message: ".searchable isn't available on iOS 13")
 public static let v13 = Self.unavailable()
 @available(*, unavailable, message: ".searchable isn't available on iOS 14")
 public static let v14 = Self.unavailable()
 public static let v15 = Self(for: .v15, selector: selector)
 public static let v16 = Self(for: .v16, selector: selector)
 public static let v17 = Self(for: .v17, selector: selector)
 private static var selector: IntrospectionSelector<UISearchBar> {
 .from(UISplitViewController.self) {
 0ドル.viewIfLoaded?.allDescendants.lazy.compactMap { 0ドル as? UISearchBar }.first
 }
 }
}
extension tvOSViewVersion<SearchFieldSplitViewType, UISearchBar> {
 @available(*, unavailable, message: ".searchable isn't available on tvOS 13")
 public static let v13 = Self.unavailable()
 @available(*, unavailable, message: ".searchable isn't available on tvOS 14")
 public static let v14 = Self.unavailable()
 public static let v15 = Self(for: .v15, selector: selector)
 public static let v16 = Self(for: .v16, selector: selector)
 public static let v17 = Self(for: .v17, selector: selector)
 private static var selector: IntrospectionSelector<UISearchBar> {
 .from(UISplitViewController.self) {
 0ドル.viewIfLoaded?.allDescendants.lazy.compactMap { 0ドル as? UISearchBar }.first
 }
 }
}
extension visionOSViewVersion<SearchFieldSplitViewType, UISearchBar> {
 public static let v1 = Self(for: .v1, selector: selector)
 private static var selector: IntrospectionSelector<UISearchBar> {
 .from(UISplitViewController.self) {
 0ドル.viewIfLoaded?.allDescendants.lazy.compactMap { 0ドル as? UISearchBar }.first
 }
 }
}
#endif
#endif
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /