Add .introspectSplitViewController() on iOS (#89)

This commit is contained in:
JannThomas 2021-03-23 19:45:00 +01:00 committed by GitHub
parent f4f5e32df3
commit c38e70e82b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View File

@ -3,6 +3,7 @@ Changelog
## master
- Added `.introspectSplitViewController()` on iOS
- Fixed iPad tests
- Added iPad to CI
- Added `.introspectColorWell()` on iOS and macOS

View File

@ -48,7 +48,7 @@ public enum Introspect {
return typed
}
}
return nil
return root as? AnyViewControllerType
}
/// Finds a subview of the specified type.

View File

@ -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.
public func introspectViewController(customize: @escaping (UIViewController) -> ()) -> some View {
return inject(UIKitIntrospectionViewController(

View File

@ -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, *)
private struct ViewControllerTestView: View {
let spy: () -> Void
@ -477,6 +493,16 @@ class UIKitTests: XCTestCase {
}
#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() {
let expectation = XCTestExpectation()