Add .introspectSplitViewController() on iOS (#89)
This commit is contained in:
parent
f4f5e32df3
commit
c38e70e82b
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Workspace
|
||||||
|
version = "1.0">
|
||||||
|
<FileRef
|
||||||
|
location = "self:">
|
||||||
|
</FileRef>
|
||||||
|
</Workspace>
|
|
@ -3,6 +3,7 @@ Changelog
|
||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
- Added `.introspectSplitViewController()` on iOS
|
||||||
- Fixed iPad tests
|
- Fixed iPad tests
|
||||||
- Added iPad to CI
|
- Added iPad to CI
|
||||||
- Added `.introspectColorWell()` on iOS and macOS
|
- Added `.introspectColorWell()` on iOS and macOS
|
||||||
|
|
|
@ -48,7 +48,7 @@ public enum Introspect {
|
||||||
return typed
|
return typed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return root as? AnyViewControllerType
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds a subview of the specified type.
|
/// Finds a subview of the specified type.
|
||||||
|
|
|
@ -45,6 +45,23 @@ extension View {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Finds a `UISplitViewController` from a `SwiftUI.NavigationView` with style `DoubleColumnNavigationViewStyle`.
|
||||||
|
public func introspectSplitViewController(customize: @escaping (UISplitViewController) -> ()) -> some View {
|
||||||
|
return inject(UIKitIntrospectionViewController(
|
||||||
|
selector: { introspectionViewController in
|
||||||
|
|
||||||
|
// Search in ancestors
|
||||||
|
if let splitViewController = introspectionViewController.splitViewController {
|
||||||
|
return splitViewController
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search in siblings
|
||||||
|
return Introspect.previousSibling(containing: UISplitViewController.self, from: introspectionViewController)
|
||||||
|
},
|
||||||
|
customize: customize
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
/// Finds the containing `UIViewController` of a SwiftUI view.
|
/// Finds the containing `UIViewController` of a SwiftUI view.
|
||||||
public func introspectViewController(customize: @escaping (UIViewController) -> ()) -> some View {
|
public func introspectViewController(customize: @escaping (UIViewController) -> ()) -> some View {
|
||||||
return inject(UIKitIntrospectionViewController(
|
return inject(UIKitIntrospectionViewController(
|
||||||
|
|
|
@ -49,6 +49,22 @@ private struct NavigationTestView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(iOS 13.0, tvOS 13.0, macOS 10.15.0, *)
|
||||||
|
private struct SplitNavigationTestView: View {
|
||||||
|
let spy: () -> Void
|
||||||
|
var body: some View {
|
||||||
|
NavigationView {
|
||||||
|
VStack {
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationViewStyle(DoubleColumnNavigationViewStyle())
|
||||||
|
.introspectSplitViewController { navigationController in
|
||||||
|
self.spy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@available(iOS 13.0, tvOS 13.0, macOS 10.15.0, *)
|
@available(iOS 13.0, tvOS 13.0, macOS 10.15.0, *)
|
||||||
private struct ViewControllerTestView: View {
|
private struct ViewControllerTestView: View {
|
||||||
let spy: () -> Void
|
let spy: () -> Void
|
||||||
|
@ -477,6 +493,16 @@ class UIKitTests: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
|
func testSplitNavigation() {
|
||||||
|
|
||||||
|
let expectation = XCTestExpectation()
|
||||||
|
let view = SplitNavigationTestView(spy: {
|
||||||
|
expectation.fulfill()
|
||||||
|
})
|
||||||
|
TestUtils.present(view: view)
|
||||||
|
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
|
||||||
|
}
|
||||||
|
|
||||||
func testRootNavigation() {
|
func testRootNavigation() {
|
||||||
|
|
||||||
let expectation = XCTestExpectation()
|
let expectation = XCTestExpectation()
|
||||||
|
|
Loading…
Reference in New Issue