|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +/// An abstract representation of a presented view's type in SwiftUI. |
| 4 | +/// |
| 5 | +/// ### iOS |
| 6 | +/// |
| 7 | +/// ```swift |
| 8 | +/// struct ContentView: View { |
| 9 | +/// var body: some View { |
| 10 | +/// Presentation { |
| 11 | +/// Text("Item 1") |
| 12 | +/// Text("Item 2") |
| 13 | +/// Text("Item 3") |
| 14 | +/// } |
| 15 | +/// .introspect(.form, on: .iOS(.v13, .v14, .v15)) { |
| 16 | +/// print(type(of: $0)) // UITableView |
| 17 | +/// } |
| 18 | +/// .introspect(.form, on: .iOS(.v16, .v17)) { |
| 19 | +/// print(type(of: $0)) // UICollectionView |
| 20 | +/// } |
| 21 | +/// } |
| 22 | +/// } |
| 23 | +/// ``` |
| 24 | +/// |
| 25 | +/// ### tvOS |
| 26 | +/// |
| 27 | +/// ```swift |
| 28 | +/// struct ContentView: View { |
| 29 | +/// var body: some View { |
| 30 | +/// Presentation { |
| 31 | +/// Text("Item 1") |
| 32 | +/// Text("Item 2") |
| 33 | +/// Text("Item 3") |
| 34 | +/// } |
| 35 | +/// .introspect(.form, on: .tvOS(.v13, .v14, .v15, .v16, .v17)) { |
| 36 | +/// print(type(of: $0)) // UITableView |
| 37 | +/// } |
| 38 | +/// } |
| 39 | +/// } |
| 40 | +/// ``` |
| 41 | +/// |
| 42 | +/// ### macOS |
| 43 | +/// |
| 44 | +/// Not available. |
| 45 | +/// |
| 46 | +public struct PresentationType: IntrospectableViewType {} |
| 47 | + |
| 48 | +#if os(iOS) || os(tvOS) |
| 49 | +extension IntrospectableViewType where Self == PresentationType { |
| 50 | + public static var presentation: Self { .init() } |
| 51 | +} |
| 52 | + |
| 53 | +#if canImport(UIKit) |
| 54 | +extension iOSViewVersion<PresentationType, UIPresentationController> { |
| 55 | + public static let v13 = Self(for: .v13, selector: selector) |
| 56 | + public static let v14 = Self(for: .v14, selector: selector) |
| 57 | + public static let v15 = Self(for: .v15, selector: selector) |
| 58 | + public static let v16 = Self(for: .v16, selector: selector) |
| 59 | + public static let v17 = Self(for: .v17, selector: selector) |
| 60 | + |
| 61 | + private static var selector: IntrospectionSelector<UIPresentationController> { |
| 62 | + .default.withAncestorSelector(\.presentationController) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +extension tvOSViewVersion<PresentationType, UIPresentationController> { |
| 67 | + public static let v13 = Self(for: .v13, selector: selector) |
| 68 | + public static let v14 = Self(for: .v14, selector: selector) |
| 69 | + public static let v15 = Self(for: .v15, selector: selector) |
| 70 | + public static let v16 = Self(for: .v16, selector: selector) |
| 71 | + public static let v17 = Self(for: .v17, selector: selector) |
| 72 | + |
| 73 | + private static var selector: IntrospectionSelector<UIPresentationController> { |
| 74 | + .default.withAncestorSelector(\.presentationController) |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +extension UIPresentationController: PlatformEntity { |
| 79 | + @_spi(Internals) |
| 80 | + public var ancestor: UIPresentationController? { |
| 81 | + nil |
| 82 | + } |
| 83 | + |
| 84 | + @_spi(Internals) |
| 85 | + public var descendants: [UIPresentationController] { |
| 86 | + [] |
| 87 | + } |
| 88 | + |
| 89 | + @_spi(Internals) |
| 90 | + public func isDescendant(of other: UIPresentationController) -> Bool { |
| 91 | + false |
| 92 | + } |
| 93 | +} |
| 94 | +#endif |
| 95 | +#endif |
0 commit comments