Skip to content

Commit 231c004

Browse files
committed
WIP
1 parent aba2ea9 commit 231c004

File tree

3 files changed

+118
-79
lines changed

3 files changed

+118
-79
lines changed

Examples/Showcase/Showcase.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
D53071F929983CEF00F1936C /* AppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53071F829983CEF00F1936C /* AppView.swift */; };
1212
D5B829752999738200920EBD /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B829742999738200920EBD /* Helpers.swift */; };
1313
D5B864E82E72BF0F002F5243 /* ScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B864E72E72BF0F002F5243 /* ScrollView.swift */; };
14+
D5B864EA2E72CE71002F5243 /* List.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B864E92E72CE71002F5243 /* List.swift */; };
1415
D5E3180329C132B6005847DC /* SwiftUIIntrospect in Frameworks */ = {isa = PBXBuildFile; productRef = D5E3180229C132B6005847DC /* SwiftUIIntrospect */; };
1516
/* End PBXBuildFile section */
1617

@@ -21,6 +22,7 @@
2122
D530720429983D9300F1936C /* Showcase.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Showcase.entitlements; sourceTree = "<group>"; };
2223
D5B829742999738200920EBD /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
2324
D5B864E72E72BF0F002F5243 /* ScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollView.swift; sourceTree = "<group>"; };
25+
D5B864E92E72CE71002F5243 /* List.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = List.swift; sourceTree = "<group>"; };
2426
/* End PBXFileReference section */
2527

2628
/* Begin PBXFrameworksBuildPhase section */
@@ -58,6 +60,7 @@
5860
D530720429983D9300F1936C /* Showcase.entitlements */,
5961
D53071F629983CEF00F1936C /* App.swift */,
6062
D53071F829983CEF00F1936C /* AppView.swift */,
63+
D5B864E92E72CE71002F5243 /* List.swift */,
6164
D5B864E72E72BF0F002F5243 /* ScrollView.swift */,
6265
D5B829742999738200920EBD /* Helpers.swift */,
6366
);
@@ -145,6 +148,7 @@
145148
D53071F929983CEF00F1936C /* AppView.swift in Sources */,
146149
D5B864E82E72BF0F002F5243 /* ScrollView.swift in Sources */,
147150
D5B829752999738200920EBD /* Helpers.swift in Sources */,
151+
D5B864EA2E72CE71002F5243 /* List.swift in Sources */,
148152
D53071F729983CEF00F1936C /* App.swift in Sources */,
149153
);
150154
runOnlyForDeploymentPostprocessing = 0;

Examples/Showcase/Showcase/AppView.swift

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ struct ContentView: View {
2727
ListShowcase()
2828
.tabItem { Text("List") }
2929
.tag(0)
30-
ScrollViewShowcase()
31-
.tabItem { Text("ScrollView") }
32-
.tag(1)
3330
#if !os(macOS)
3431
NavigationShowcase()
3532
.tabItem { Text("Navigation") }
36-
.tag(2)
33+
.tag(1)
3734
PresentationShowcase()
3835
.tabItem { Text("Presentation") }
39-
.tag(3)
36+
.tag(2)
4037
#endif
41-
GenericViewShowcase()
42-
.tabItem { Text("Generic View") }
43-
.tag(4)
38+
ScrollViewShowcase()
39+
.tabItem { Text("ScrollView") }
40+
.tag(3)
4441
SimpleElementsShowcase()
4542
.tabItem { Text("Simple elements") }
43+
.tag(4)
44+
UIViewRepresentableShowcase()
45+
.tabItem { Text("UIViewRepresentables") }
4646
.tag(5)
4747
}
4848
#if os(iOS) || os(tvOS)
@@ -58,76 +58,6 @@ struct ContentView: View {
5858
}
5959
}
6060

61-
struct ListShowcase: View {
62-
var body: some View {
63-
VStack(spacing: 40) {
64-
VStack {
65-
Text("Default")
66-
.lineLimit(1)
67-
.minimumScaleFactor(0.5)
68-
.padding(.horizontal, 12)
69-
List {
70-
Text("Item 1")
71-
Text("Item 2")
72-
}
73-
}
74-
75-
VStack {
76-
Text(".introspect(.list, ...)")
77-
.lineLimit(1)
78-
.minimumScaleFactor(0.5)
79-
.padding(.horizontal, 12)
80-
.font(.system(.subheadline, design: .monospaced))
81-
List {
82-
Text("Item 1")
83-
Text("Item 2")
84-
}
85-
#if os(iOS) || os(tvOS) || os(visionOS)
86-
.introspect(.list, on: .iOS(.v13, .v14, .v15), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26)) { tableView in
87-
tableView.backgroundView = UIView()
88-
tableView.backgroundColor = .cyan
89-
}
90-
.introspect(.list, on: .iOS(.v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26)) { collectionView in
91-
collectionView.backgroundView = UIView()
92-
collectionView.subviews.dropFirst(1).first?.backgroundColor = .cyan
93-
}
94-
#elseif os(macOS)
95-
.introspect(.list, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26)) { tableView in
96-
tableView.backgroundColor = .cyan
97-
}
98-
#endif
99-
}
100-
101-
VStack {
102-
Text(".introspect(.list, ..., scope: .ancestor)")
103-
.lineLimit(1)
104-
.minimumScaleFactor(0.5)
105-
.padding(.horizontal, 12)
106-
.font(.system(.subheadline, design: .monospaced))
107-
List {
108-
Text("Item 1")
109-
Text("Item 2")
110-
#if os(iOS) || os(tvOS) || os(visionOS)
111-
.introspect(.list, on: .iOS(.v13, .v14, .v15), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), scope: .ancestor) { tableView in
112-
tableView.backgroundView = UIView()
113-
tableView.backgroundColor = .cyan
114-
}
115-
.introspect(.list, on: .iOS(.v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), scope: .ancestor) { collectionView in
116-
collectionView.backgroundView = UIView()
117-
collectionView.subviews.dropFirst(1).first?.backgroundColor = .cyan
118-
}
119-
#elseif os(macOS)
120-
.introspect(.list, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), scope: .ancestor) { tableView in
121-
tableView.backgroundColor = .cyan
122-
}
123-
#endif
124-
}
125-
}
126-
}
127-
128-
}
129-
}
130-
13161
struct NavigationShowcase: View {
13262
var body: some View {
13363
NavigationView {
@@ -236,7 +166,7 @@ struct PresentationShowcase: View {
236166
}
237167
#endif
238168

239-
struct GenericViewShowcase: View {
169+
struct UIViewRepresentableShowcase: View {
240170
var body: some View {
241171
VStack(spacing: 10) {
242172
Text(".introspect(.view, ...)")
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import SwiftUI
2+
import SwiftUIIntrospect
3+
4+
struct ListShowcase: View {
5+
@State var receiverListFound: Bool = false
6+
@State var ancestorListFound: Bool = false
7+
8+
var body: some View {
9+
VStack(spacing: 40) {
10+
VStack {
11+
Text("Default")
12+
.lineLimit(1)
13+
.minimumScaleFactor(0.5)
14+
.padding(.horizontal, 12)
15+
List {
16+
Text("Item 1")
17+
Text("Item 2")
18+
}
19+
}
20+
21+
VStack {
22+
Text(".introspect(.list, ...)")
23+
.lineLimit(1)
24+
.minimumScaleFactor(0.5)
25+
.padding(.horizontal, 12)
26+
.font(.system(.subheadline, design: .monospaced))
27+
List {
28+
Text("Item 1")
29+
Text("Item 2")
30+
}
31+
.modifier { list in
32+
if #available(iOS 16, *) {
33+
list.background {
34+
if receiverListFound {
35+
Color(uiColor: .cyan)
36+
}
37+
}
38+
.scrollContentBackground(.hidden)
39+
} else {
40+
list
41+
}
42+
}
43+
#if os(iOS) || os(tvOS) || os(visionOS)
44+
.introspect(.list, on: .iOS(.v13, .v14, .v15), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26)) { tableView in
45+
tableView.backgroundView = UIView()
46+
tableView.backgroundColor = .cyan
47+
}
48+
.introspect(.list, on: .iOS(.v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26)) { collectionView in
49+
DispatchQueue.main.async {
50+
receiverListFound = true
51+
}
52+
}
53+
#elseif os(macOS)
54+
.introspect(.list, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26)) { tableView in
55+
DispatchQueue.main.async {
56+
receiverListFound = true
57+
}
58+
}
59+
#endif
60+
}
61+
62+
VStack {
63+
Text(".introspect(.list, ..., scope: .ancestor)")
64+
.lineLimit(1)
65+
.minimumScaleFactor(0.5)
66+
.padding(.horizontal, 12)
67+
.font(.system(.subheadline, design: .monospaced))
68+
List {
69+
Text("Item 1")
70+
Text("Item 2")
71+
#if os(iOS) || os(tvOS) || os(visionOS)
72+
.introspect(.list, on: .iOS(.v13, .v14, .v15), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), scope: .ancestor) { tableView in
73+
tableView.backgroundView = UIView()
74+
tableView.backgroundColor = .cyan
75+
}
76+
.introspect(.list, on: .iOS(.v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), scope: .ancestor) { collectionView in
77+
DispatchQueue.main.async {
78+
ancestorListFound = true
79+
}
80+
}
81+
#elseif os(macOS)
82+
.introspect(.list, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), scope: .ancestor) { tableView in
83+
DispatchQueue.main.async {
84+
ancestorListFound = true
85+
}
86+
}
87+
#endif
88+
}
89+
.modifier { list in
90+
if #available(iOS 16, *) {
91+
list.background {
92+
if ancestorListFound {
93+
Color(uiColor: .cyan)
94+
}
95+
}
96+
.scrollContentBackground(.hidden)
97+
} else {
98+
list
99+
}
100+
}
101+
}
102+
}
103+
104+
}
105+
}

0 commit comments

Comments
 (0)