|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +/// An abstract representation of the receiving SwiftUI view's view controller, |
| 4 | +/// or the closest ancestor view controller if missing. |
| 5 | +/// |
| 6 | +/// ### iOS |
| 7 | +/// |
| 8 | +/// ```swift |
| 9 | +/// struct ContentView: View { |
| 10 | +/// var body: some View { |
| 11 | +/// NavigationView { |
| 12 | +/// Text("Root").frame(maxWidth: .infinity, maxHeight: .infinity).background(Color.red) |
| 13 | +/// .introspect(.viewController, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { |
| 14 | +/// print(type(of: $0)) // some subclass of UIHostingController |
| 15 | +/// } |
| 16 | +/// } |
| 17 | +/// .navigationViewStyle(.stack) |
| 18 | +/// .introspect(.viewController, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { |
| 19 | +/// print(type(of: $0)) // UINavigationController |
| 20 | +/// } |
| 21 | +/// } |
| 22 | +/// } |
| 23 | +/// ``` |
| 24 | +/// |
| 25 | +/// ### tvOS |
| 26 | +/// |
| 27 | +/// ```swift |
| 28 | +/// struct ContentView: View { |
| 29 | +/// var body: some View { |
| 30 | +/// NavigationView { |
| 31 | +/// Text("Root").frame(maxWidth: .infinity, maxHeight: .infinity).background(Color.red) |
| 32 | +/// .introspect(.viewController, on: .tvOS(.v13, .v14, .v15, .v16, .v17)) { |
| 33 | +/// print(type(of: $0)) // some subclass of UIHostingController |
| 34 | +/// } |
| 35 | +/// } |
| 36 | +/// .navigationViewStyle(.stack) |
| 37 | +/// .introspect(.viewController, on: .tvOS(.v13, .v14, .v15, .v16, .v17)) { |
| 38 | +/// print(type(of: $0)) // UINavigationController |
| 39 | +/// } |
| 40 | +/// } |
| 41 | +/// } |
| 42 | +/// ``` |
| 43 | +/// |
| 44 | +/// ### macOS |
| 45 | +/// |
| 46 | +/// Not available. |
| 47 | +/// |
| 48 | +public struct ViewControllerType: IntrospectableViewType { |
| 49 | + public var scope: IntrospectionScope { [.receiver, .ancestor] } |
| 50 | +} |
| 51 | + |
| 52 | +extension IntrospectableViewType where Self == ViewControllerType { |
| 53 | + public static var viewController: Self { .init() } |
| 54 | +} |
| 55 | + |
| 56 | +#if canImport(UIKit) |
| 57 | +extension iOSViewVersion<ViewControllerType, UIViewController> { |
| 58 | + public static let v13 = Self(for: .v13) |
| 59 | + public static let v14 = Self(for: .v14) |
| 60 | + public static let v15 = Self(for: .v15) |
| 61 | + public static let v16 = Self(for: .v16) |
| 62 | + public static let v17 = Self(for: .v17) |
| 63 | +} |
| 64 | + |
| 65 | +extension tvOSViewVersion<ViewControllerType, UIViewController> { |
| 66 | + public static let v13 = Self(for: .v13) |
| 67 | + public static let v14 = Self(for: .v14) |
| 68 | + public static let v15 = Self(for: .v15) |
| 69 | + public static let v16 = Self(for: .v16) |
| 70 | + public static let v17 = Self(for: .v17) |
| 71 | +} |
| 72 | +#endif |
0 commit comments