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
|
||||
navigationController.navigationBar.backgroundColor = .cyan
|
||||
}
|
||||
#endif
|
||||
.introspect(.searchField, on: .iOS(.v15, .v16), .tvOS(.v15, .v16)) { searchBar in
|
||||
searchBar.backgroundColor = .red
|
||||
#if os(iOS)
|
||||
.introspect(.searchField, on: .iOS(.v15, .v16)) { searchController in
|
||||
searchController.searchBar.backgroundColor = .red
|
||||
#if os(iOS)
|
||||
searchController.searchBar.searchTextField.backgroundColor = .purple
|
||||
searchBar.searchTextField.backgroundColor = .purple
|
||||
#endif
|
||||
}
|
||||
#elseif os(tvOS)
|
||||
.introspect(.searchField, on: .tvOS(.v15, .v16)) { searchField in
|
||||
searchField.backgroundColor = .red
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@ extension IntrospectableViewType where Self == SearchFieldType {
|
|||
}
|
||||
|
||||
#if canImport(UIKit)
|
||||
@available(tvOS, unavailable)
|
||||
extension iOSViewVersion<SearchFieldType, UISearchController> {
|
||||
extension iOSViewVersion<SearchFieldType, 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")
|
||||
|
@ -18,9 +17,9 @@ extension iOSViewVersion<SearchFieldType, UISearchController> {
|
|||
public static let v15 = Self(for: .v15, 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) {
|
||||
$0.navigationBar.topItem?.searchController
|
||||
$0.view.allDescendants.lazy.compactMap { $0 as? UISearchBar }.first
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,15 @@ import SwiftUI
|
|||
import SwiftUIIntrospect
|
||||
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 {
|
||||
#if canImport(UIKit) && os(iOS)
|
||||
typealias PlatformSearchField = UISearchController
|
||||
#elseif canImport(UIKit) && os(tvOS)
|
||||
#if canImport(UIKit)
|
||||
typealias PlatformSearchField = UISearchBar
|
||||
#endif
|
||||
|
||||
func testSearchField() throws {
|
||||
guard #available(iOS 15, tvOS 15, *) else {
|
||||
func testSearchFieldInNavigationStack() throws {
|
||||
guard #available(iOS 15, tvOS 16, *) else {
|
||||
throw XCTSkip()
|
||||
}
|
||||
|
||||
|
@ -32,8 +31,8 @@ final class SearchFieldTests: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
func testSearchFieldAsAncestor() throws {
|
||||
guard #available(iOS 15, tvOS 15, *) else {
|
||||
func testSearchFieldInNavigationStackAsAncestor() throws {
|
||||
guard #available(iOS 15, tvOS 16, *) else {
|
||||
throw XCTSkip()
|
||||
}
|
||||
|
||||
|
@ -52,5 +51,47 @@ final class SearchFieldTests: XCTestCase {
|
|||
.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
|
||||
|
|
Loading…
Reference in New Issue