diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ffae6f..41efcd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Changelog ## master +- Added `.introspectSplitViewController()` on iOS - Fixed iPad tests - Added iPad to CI - Added `.introspectColorWell()` on iOS and macOS diff --git a/Introspect/Introspect.swift b/Introspect/Introspect.swift index 1b305be..cbc7562 100644 --- a/Introspect/Introspect.swift +++ b/Introspect/Introspect.swift @@ -48,7 +48,7 @@ public enum Introspect { return typed } } - return nil + return root as? AnyViewControllerType } /// Finds a subview of the specified type. diff --git a/Introspect/ViewExtensions.swift b/Introspect/ViewExtensions.swift index 3f40c45..9b52c36 100644 --- a/Introspect/ViewExtensions.swift +++ b/Introspect/ViewExtensions.swift @@ -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( diff --git a/IntrospectTests/UIKitTests.swift b/IntrospectTests/UIKitTests.swift index b37473c..8f22333 100644 --- a/IntrospectTests/UIKitTests.swift +++ b/IntrospectTests/UIKitTests.swift @@ -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()