wip
This commit is contained in:
parent
4af686c887
commit
cfb5414557
|
@ -186,18 +186,12 @@ struct NavigationShowcase: View {
|
||||||
.introspect(.navigationView(style: .columns), on: .tvOS(.v13, .v14, .v15, .v16)) { navigationController in
|
.introspect(.navigationView(style: .columns), on: .tvOS(.v13, .v14, .v15, .v16)) { navigationController in
|
||||||
navigationController.navigationBar.backgroundColor = .cyan
|
navigationController.navigationBar.backgroundColor = .cyan
|
||||||
}
|
}
|
||||||
#endif
|
.introspect(.searchField, on: .iOS(.v15, .v16), .tvOS(.v15, .v16)) { searchBar in
|
||||||
#if os(iOS)
|
searchBar.backgroundColor = .red
|
||||||
.introspect(.searchField, on: .iOS(.v15, .v16)) { searchController in
|
|
||||||
searchController.searchBar.backgroundColor = .red
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
searchController.searchBar.searchTextField.backgroundColor = .purple
|
searchBar.searchTextField.backgroundColor = .purple
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#elseif os(tvOS)
|
|
||||||
.introspect(.searchField, on: .tvOS(.v15, .v16)) { searchField in
|
|
||||||
searchField.backgroundColor = .red
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,7 @@ extension IntrospectableViewType where Self == SearchFieldType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if canImport(UIKit)
|
#if canImport(UIKit)
|
||||||
@available(tvOS, unavailable)
|
extension iOSViewVersion<SearchFieldType, UISearchBar> {
|
||||||
extension iOSViewVersion<SearchFieldType, UISearchController> {
|
|
||||||
@available(*, unavailable, message: ".searchable isn't available on iOS 13")
|
@available(*, unavailable, message: ".searchable isn't available on iOS 13")
|
||||||
public static let v13 = Self.unavailable()
|
public static let v13 = Self.unavailable()
|
||||||
@available(*, unavailable, message: ".searchable isn't available on iOS 14")
|
@available(*, unavailable, message: ".searchable isn't available on iOS 14")
|
||||||
|
@ -18,9 +17,9 @@ extension iOSViewVersion<SearchFieldType, UISearchController> {
|
||||||
public static let v15 = Self(for: .v15, selector: selector)
|
public static let v15 = Self(for: .v15, selector: selector)
|
||||||
public static let v16 = Self(for: .v16, selector: selector)
|
public static let v16 = Self(for: .v16, selector: selector)
|
||||||
|
|
||||||
private static var selector: IntrospectionSelector<UISearchController> {
|
private static var selector: IntrospectionSelector<UISearchBar> {
|
||||||
.from(UINavigationController.self) {
|
.from(UINavigationController.self) {
|
||||||
$0.navigationBar.topItem?.searchController
|
$0.view.allDescendants.lazy.compactMap { $0 as? UISearchBar }.first
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,15 @@ import SwiftUI
|
||||||
import SwiftUIIntrospect
|
import SwiftUIIntrospect
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
@available(iOS 15, tvOS 15, *)
|
// FIXME: crashes on tvOS 15, tests only... perhaps has to do with TestUtils?
|
||||||
|
@available(iOS 15, tvOS 16, *)
|
||||||
final class SearchFieldTests: XCTestCase {
|
final class SearchFieldTests: XCTestCase {
|
||||||
#if canImport(UIKit) && os(iOS)
|
#if canImport(UIKit)
|
||||||
typealias PlatformSearchField = UISearchController
|
|
||||||
#elseif canImport(UIKit) && os(tvOS)
|
|
||||||
typealias PlatformSearchField = UISearchBar
|
typealias PlatformSearchField = UISearchBar
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
func testSearchField() throws {
|
func testSearchFieldInNavigationStack() throws {
|
||||||
guard #available(iOS 15, tvOS 15, *) else {
|
guard #available(iOS 15, tvOS 16, *) else {
|
||||||
throw XCTSkip()
|
throw XCTSkip()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +31,8 @@ final class SearchFieldTests: XCTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSearchFieldAsAncestor() throws {
|
func testSearchFieldInNavigationStackAsAncestor() throws {
|
||||||
guard #available(iOS 15, tvOS 15, *) else {
|
guard #available(iOS 15, tvOS 16, *) else {
|
||||||
throw XCTSkip()
|
throw XCTSkip()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,5 +51,47 @@ final class SearchFieldTests: XCTestCase {
|
||||||
.navigationViewStyle(.stack)
|
.navigationViewStyle(.stack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testSearchFieldInNavigationSplitView() throws {
|
||||||
|
guard #available(iOS 15, tvOS 16, *) else {
|
||||||
|
throw XCTSkip()
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertViewIntrospection(of: PlatformSearchField.self) { spies in
|
||||||
|
let spy = spies[0]
|
||||||
|
|
||||||
|
NavigationView {
|
||||||
|
Text("Customized")
|
||||||
|
.searchable(text: .constant(""))
|
||||||
|
}
|
||||||
|
.navigationViewStyle(DoubleColumnNavigationViewStyle())
|
||||||
|
#if os(iOS)
|
||||||
|
.introspect(.searchField, on: .iOS(.v15, .v16), customize: spy)
|
||||||
|
#elseif os(tvOS)
|
||||||
|
.introspect(.searchField, on: .tvOS(.v15, .v16), customize: spy)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSearchFieldInNavigationSplitViewAsAncestor() throws {
|
||||||
|
guard #available(iOS 15, tvOS 15, *) else {
|
||||||
|
throw XCTSkip()
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertViewIntrospection(of: PlatformSearchField.self) { spies in
|
||||||
|
let spy = spies[0]
|
||||||
|
|
||||||
|
NavigationView {
|
||||||
|
Text("Customized")
|
||||||
|
.searchable(text: .constant(""))
|
||||||
|
#if os(iOS)
|
||||||
|
.introspect(.searchField, on: .iOS(.v15, .v16), scope: .ancestor, customize: spy)
|
||||||
|
#elseif os(tvOS)
|
||||||
|
.introspect(.searchField, on: .tvOS(.v15, .v16), scope: .ancestor, customize: spy)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
.navigationViewStyle(DoubleColumnNavigationViewStyle())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue