Skip to content

Commit 8136027

Browse files
committed
wip
1 parent 63c3199 commit 8136027

File tree

5 files changed

+213
-74
lines changed

5 files changed

+213
-74
lines changed

Sources/ViewTypes/Sheet.swift

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import SwiftUI
2+
3+
/// An abstract representation of `.sheet` in SwiftUI.
4+
///
5+
/// ### iOS
6+
///
7+
/// ```swift
8+
/// public struct ContentView: View {
9+
/// @State var isPresented = false
10+
///
11+
/// public var body: some View {
12+
/// Button("Present", action: { isPresented = true })
13+
/// .sheet(isPresented: $isPresented) {
14+
/// Button("Dismiss", action: { isPresented = false })
15+
/// .introspect(.sheet, on: .iOS(.v14, .v15, .v16, .v17)) {
16+
/// print(type(of: $0)) // UISheetPresentationController
17+
/// }
18+
/// }
19+
/// }
20+
/// }
21+
/// ```
22+
///
23+
/// ### tvOS
24+
///
25+
/// ```swift
26+
/// public struct ContentView: View {
27+
/// @State var isPresented = false
28+
///
29+
/// public var body: some View {
30+
/// Button("Present", action: { isPresented = true })
31+
/// .sheet(isPresented: $isPresented) {
32+
/// Button("Dismiss", action: { isPresented = false })
33+
/// .introspect(.sheet, on: .tvOS(.v14, .v15, .v16, .v17)) {
34+
/// print(type(of: $0)) // UISheetPresentationController
35+
/// }
36+
/// }
37+
/// }
38+
/// }
39+
/// ```
40+
///
41+
/// ### macOS
42+
///
43+
/// Not available.
44+
///
45+
public struct SheetType: IntrospectableViewType {
46+
public var scope: IntrospectionScope { .ancestor }
47+
}
48+
49+
#if os(iOS) || os(tvOS)
50+
extension IntrospectableViewType where Self == SheetType {
51+
public static var sheet: Self { .init() }
52+
}
53+
54+
#if canImport(UIKit)
55+
extension iOSViewVersion<SheetType, UIPresentationController> {
56+
public static let v13 = Self(for: .v13, selector: selector)
57+
public static let v14 = Self(for: .v14, selector: selector)
58+
59+
private static var selector: IntrospectionSelector<UIPresentationController> {
60+
.from(UIViewController.self, selector: \.presentationController)
61+
}
62+
}
63+
64+
@available(iOS 15, *)
65+
@available(tvOS, unavailable)
66+
extension iOSViewVersion<SheetType, UISheetPresentationController> {
67+
public static let v15 = Self(for: .v15, selector: selector)
68+
public static let v16 = Self(for: .v16, selector: selector)
69+
public static let v17 = Self(for: .v17, selector: selector)
70+
71+
private static var selector: IntrospectionSelector<UISheetPresentationController> {
72+
.from(UIViewController.self, selector: \.sheetPresentationController)
73+
}
74+
}
75+
76+
extension tvOSViewVersion<SheetType, UIPresentationController> {
77+
public static let v13 = Self(for: .v13, selector: selector)
78+
public static let v14 = Self(for: .v14, selector: selector)
79+
public static let v15 = Self(for: .v15, selector: selector)
80+
public static let v16 = Self(for: .v16, selector: selector)
81+
public static let v17 = Self(for: .v17, selector: selector)
82+
83+
private static var selector: IntrospectionSelector<UIPresentationController> {
84+
.from(UIViewController.self, selector: \.presentationController)
85+
}
86+
}
87+
#endif
88+
#endif

Tests/Tests.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
D58CE15629C621B30081BFB0 /* SwiftUIIntrospect in Frameworks */ = {isa = PBXBuildFile; productRef = D58CE15529C621B30081BFB0 /* SwiftUIIntrospect */; };
9797
D58CE15829C621DD0081BFB0 /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = D58CE15729C621DD0081BFB0 /* TestUtils.swift */; };
9898
D5AD0D912A114B98003D8DEC /* TextFieldWithVerticalAxisTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AD0D902A114B98003D8DEC /* TextFieldWithVerticalAxisTests.swift */; };
99-
D5ADFACC2A4A22AE009494FD /* PresentationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5ADFACB2A4A22AE009494FD /* PresentationTests.swift */; };
99+
D5ADFACC2A4A22AE009494FD /* SheetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5ADFACB2A4A22AE009494FD /* SheetTests.swift */; };
100+
D5ADFACE2A4A3482009494FD /* FullScreenCoverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5ADFACD2A4A3482009494FD /* FullScreenCoverTests.swift */; };
100101
D5B67B842A0D318F007D5D9B /* TextFieldTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B67B832A0D318F007D5D9B /* TextFieldTests.swift */; };
101102
D5F0BE4D29C0DBE800AD95AB /* TestsHostApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F0BE4C29C0DBE800AD95AB /* TestsHostApp.swift */; };
102103
D5F0BE6A29C0DC4900AD95AB /* PlatformTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F0BE6729C0DC4900AD95AB /* PlatformTests.swift */; };
@@ -174,7 +175,8 @@
174175
D58547F92A1D12270068ADF4 /* NavigationSplitViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationSplitViewTests.swift; sourceTree = "<group>"; };
175176
D58CE15729C621DD0081BFB0 /* TestUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestUtils.swift; sourceTree = "<group>"; };
176177
D5AD0D902A114B98003D8DEC /* TextFieldWithVerticalAxisTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldWithVerticalAxisTests.swift; sourceTree = "<group>"; };
177-
D5ADFACB2A4A22AE009494FD /* PresentationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationTests.swift; sourceTree = "<group>"; };
178+
D5ADFACB2A4A22AE009494FD /* SheetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SheetTests.swift; sourceTree = "<group>"; };
179+
D5ADFACD2A4A3482009494FD /* FullScreenCoverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullScreenCoverTests.swift; sourceTree = "<group>"; };
178180
D5B67B832A0D318F007D5D9B /* TextFieldTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldTests.swift; sourceTree = "<group>"; };
179181
D5F0BE4929C0DBE800AD95AB /* TestsHostApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestsHostApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
180182
D5F0BE4C29C0DBE800AD95AB /* TestsHostApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestsHostApp.swift; sourceTree = "<group>"; };
@@ -239,6 +241,7 @@
239241
D57506912A27EE4700A628E4 /* DatePickerWithWheelStyleTests.swift */,
240242
D57506872A27CB9800A628E4 /* FormTests.swift */,
241243
D57506892A27CE7900A628E4 /* FormWithGroupedStyleTests.swift */,
244+
D5ADFACD2A4A3482009494FD /* FullScreenCoverTests.swift */,
242245
D58119C32A211B8A0081F853 /* ListCellTests.swift */,
243246
D55F448C2A1FF209003381E4 /* ListTests.swift */,
244247
D57506852A27CA4100A628E4 /* ListWithBorderedStyleTests.swift */,
@@ -254,11 +257,11 @@
254257
D57506792A27BF6C00A628E4 /* PickerWithMenuStyleTests.swift */,
255258
D57506772A27BBBD00A628E4 /* PickerWithSegmentedStyleTests.swift */,
256259
D58119D52A23AED70081F853 /* PickerWithWheelStyleTests.swift */,
257-
D5ADFACB2A4A22AE009494FD /* PresentationTests.swift */,
258260
D575069B2A27F68700A628E4 /* ProgressViewWithCircularStyleTests.swift */,
259261
D575069D2A27F80E00A628E4 /* ProgressViewWithLinearStyleTests.swift */,
260262
D50FFE8D2A17E2A400C32641 /* ScrollViewTests.swift */,
261263
D57506A12A281B9C00A628E4 /* SearchFieldTests.swift */,
264+
D5ADFACB2A4A22AE009494FD /* SheetTests.swift */,
262265
D58119CF2A23A62C0081F853 /* SliderTests.swift */,
263266
D58119D12A23A77C0081F853 /* StepperTests.swift */,
264267
D575069F2A27FC0400A628E4 /* TableTests.swift */,
@@ -562,6 +565,7 @@
562565
D575067A2A27BF6C00A628E4 /* PickerWithMenuStyleTests.swift in Sources */,
563566
D57506922A27EE4700A628E4 /* DatePickerWithWheelStyleTests.swift in Sources */,
564567
D57506822A27C74600A628E4 /* ListWithInsetGroupedStyleTests.swift in Sources */,
568+
D5ADFACE2A4A3482009494FD /* FullScreenCoverTests.swift in Sources */,
565569
D568532C2A49DBB10039A99F /* SignInWithAppleButtonTests.swift in Sources */,
566570
D575068A2A27CE7900A628E4 /* FormWithGroupedStyleTests.swift in Sources */,
567571
D575067C2A27C24600A628E4 /* ListWithPlainStyleTests.swift in Sources */,
@@ -586,7 +590,7 @@
586590
D58CE15829C621DD0081BFB0 /* TestUtils.swift in Sources */,
587591
D57506782A27BBBD00A628E4 /* PickerWithSegmentedStyleTests.swift in Sources */,
588592
D58119CE2A23A4A70081F853 /* TabViewWithPageStyleTests.swift in Sources */,
589-
D5ADFACC2A4A22AE009494FD /* PresentationTests.swift in Sources */,
593+
D5ADFACC2A4A22AE009494FD /* SheetTests.swift in Sources */,
590594
D575069A2A27F48D00A628E4 /* DatePickerWithFieldStyleTests.swift in Sources */,
591595
D503B2AC2A49BFE300027F5F /* VideoPlayerTests.swift in Sources */,
592596
D57506A02A27FC0400A628E4 /* TableTests.swift in Sources */,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if os(iOS) || os(tvOS)
2+
import SwiftUI
3+
import SwiftUIIntrospect
4+
import XCTest
5+
6+
// FIXME: this doesn't pass, even though introspection works in the Showcase app
7+
final class FullScreenCoverTests: XCTestCase {
8+
// func testPresentationAsFullScreenCover() throws {
9+
// XCTAssertViewIntrospection(of: UIPresentationController.self) { spies in
10+
// let spy0 = spies[0]
11+
//
12+
// Text("Root")
13+
// .fullScreenCover(isPresented: .constant(true)) {
14+
// Text("Content")
15+
// #if os(iOS) || os(tvOS)
16+
// .introspect(
17+
// .fullScreenCover,
18+
// on: .iOS(.v14, .v15, .v16, .v17), .tvOS(.v14, .v15, .v16, .v17),
19+
// customize: spy0
20+
// )
21+
// #endif
22+
// }
23+
// }
24+
// }
25+
}
26+
#endif

Tests/Tests/ViewTypes/PresentationTests.swift

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#if os(iOS) || os(tvOS)
2+
import SwiftUI
3+
import SwiftUIIntrospect
4+
import XCTest
5+
6+
final class SheetTests: XCTestCase {
7+
#if os(iOS)
8+
func testSheet_beforeiOS15() throws {
9+
guard #unavailable(iOS 15, tvOS 15) else {
10+
throw XCTSkip()
11+
}
12+
13+
XCTAssertViewIntrospection(of: UIPresentationController.self) { spies in
14+
let spy0 = spies[0]
15+
16+
Text("Root")
17+
.sheet(isPresented: .constant(true)) {
18+
Text("Sheet")
19+
#if os(iOS) || os(tvOS)
20+
.introspect(
21+
.sheet,
22+
on: .iOS(.v13, .v14), .tvOS(.v13, .v14, .v15, .v16, .v17),
23+
customize: spy0
24+
)
25+
#endif
26+
}
27+
}
28+
}
29+
30+
func testSheet_iOS15AndLater() throws {
31+
guard #available(iOS 15, tvOS 15, *) else {
32+
throw XCTSkip()
33+
}
34+
35+
XCTAssertViewIntrospection(of: UISheetPresentationController.self) { spies in
36+
let spy0 = spies[0]
37+
38+
Text("Root")
39+
.sheet(isPresented: .constant(true)) {
40+
Text("Sheet")
41+
#if os(iOS) || os(tvOS)
42+
.introspect(
43+
.sheet,
44+
on: .iOS(.v15, .v16, .v17),
45+
customize: spy0
46+
)
47+
#endif
48+
}
49+
}
50+
}
51+
#elseif os(tvOS)
52+
func testSheet() throws {
53+
throw XCTSkip("FIXME: this test doesn't pass for some reason, even though introspection works in the Showcase app")
54+
55+
XCTAssertViewIntrospection(of: UIPresentationController.self) { spies in
56+
let spy0 = spies[0]
57+
58+
Text("Root")
59+
.sheet(isPresented: .constant(true)) {
60+
Text("Content")
61+
.introspect(
62+
.sheet,
63+
on: .tvOS(.v13, .v14, .v15, .v16, .v17),
64+
customize: spy0
65+
)
66+
}
67+
}
68+
}
69+
#endif
70+
71+
// #if !os(tvOS)
72+
// func testPresentationAsPopover() throws {
73+
// XCTAssertViewIntrospection(of: PlatformPresentation.self) { spies in
74+
// let spy0 = spies[0]
75+
//
76+
// Text("Root")
77+
// .popover(isPresented: .constant(true)) {
78+
// Text("Popover")
79+
// #if os(iOS) || os(tvOS)
80+
// .introspect(
81+
// .presentation,
82+
// on: .iOS(.v13, .v14, .v15, .v16, .v17), .tvOS(.v13, .v14, .v15, .v16, .v17),
83+
// customize: spy0
84+
// )
85+
// #endif
86+
// }
87+
// }
88+
// }
89+
// #endif
90+
}
91+
#endif

0 commit comments

Comments
 (0)