Skip to content

Commit 0f0d00c

Browse files
committed
WIP
1 parent cabf02b commit 0f0d00c

File tree

4 files changed

+79
-67
lines changed

4 files changed

+79
-67
lines changed

Examples/Showcase/Showcase.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
D53071F729983CEF00F1936C /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53071F629983CEF00F1936C /* App.swift */; };
1111
D53071F929983CEF00F1936C /* AppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D53071F829983CEF00F1936C /* AppView.swift */; };
1212
D5B829752999738200920EBD /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B829742999738200920EBD /* Helpers.swift */; };
13+
D5B864E82E72BF0F002F5243 /* ScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B864E72E72BF0F002F5243 /* ScrollView.swift */; };
1314
D5E3180329C132B6005847DC /* SwiftUIIntrospect in Frameworks */ = {isa = PBXBuildFile; productRef = D5E3180229C132B6005847DC /* SwiftUIIntrospect */; };
1415
/* End PBXBuildFile section */
1516

@@ -19,6 +20,7 @@
1920
D53071F829983CEF00F1936C /* AppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppView.swift; sourceTree = "<group>"; };
2021
D530720429983D9300F1936C /* Showcase.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Showcase.entitlements; sourceTree = "<group>"; };
2122
D5B829742999738200920EBD /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
23+
D5B864E72E72BF0F002F5243 /* ScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollView.swift; sourceTree = "<group>"; };
2224
/* End PBXFileReference section */
2325

2426
/* Begin PBXFrameworksBuildPhase section */
@@ -56,6 +58,7 @@
5658
D530720429983D9300F1936C /* Showcase.entitlements */,
5759
D53071F629983CEF00F1936C /* App.swift */,
5860
D53071F829983CEF00F1936C /* AppView.swift */,
61+
D5B864E72E72BF0F002F5243 /* ScrollView.swift */,
5962
D5B829742999738200920EBD /* Helpers.swift */,
6063
);
6164
path = Showcase;
@@ -140,6 +143,7 @@
140143
buildActionMask = 2147483647;
141144
files = (
142145
D53071F929983CEF00F1936C /* AppView.swift in Sources */,
146+
D5B864E82E72BF0F002F5243 /* ScrollView.swift in Sources */,
143147
D5B829752999738200920EBD /* Helpers.swift in Sources */,
144148
D53071F729983CEF00F1936C /* App.swift in Sources */,
145149
);

Examples/Showcase/Showcase/AppView.swift

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -128,65 +128,6 @@ struct ListShowcase: View {
128128
}
129129
}
130130

131-
struct ScrollViewShowcase: View {
132-
var body: some View {
133-
VStack(spacing: 40) {
134-
ScrollView {
135-
Text("Default")
136-
.frame(maxWidth: .infinity)
137-
.lineLimit(1)
138-
.minimumScaleFactor(0.5)
139-
.padding(.horizontal, 12)
140-
}
141-
142-
ScrollView {
143-
Text(".introspect(.scrollView, ...)")
144-
.frame(maxWidth: .infinity)
145-
.lineLimit(1)
146-
.minimumScaleFactor(0.5)
147-
.padding(.horizontal, 12)
148-
.font(.system(.subheadline, design: .monospaced))
149-
}
150-
#if os(iOS) || os(tvOS) || os(visionOS)
151-
.introspect(
152-
.scrollView,
153-
on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26)
154-
) { scrollView in
155-
scrollView.layer.backgroundColor = UIColor.cyan.cgColor
156-
}
157-
#elseif os(macOS)
158-
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26)) { scrollView in
159-
scrollView.drawsBackground = true
160-
scrollView.backgroundColor = .cyan
161-
}
162-
#endif
163-
164-
ScrollView {
165-
Text(".introspect(.scrollView, ..., scope: .ancestor)")
166-
.frame(maxWidth: .infinity)
167-
.lineLimit(1)
168-
.minimumScaleFactor(0.5)
169-
.padding(.horizontal, 12)
170-
.font(.system(.subheadline, design: .monospaced))
171-
#if os(iOS) || os(tvOS) || os(visionOS)
172-
.introspect(
173-
.scrollView,
174-
on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26),
175-
scope: .ancestor
176-
) { scrollView in
177-
scrollView.layer.backgroundColor = UIColor.cyan.cgColor
178-
}
179-
#elseif os(macOS)
180-
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), scope: .ancestor) { scrollView in
181-
scrollView.drawsBackground = true
182-
scrollView.backgroundColor = .cyan
183-
}
184-
#endif
185-
}
186-
}
187-
}
188-
}
189-
190131
struct NavigationShowcase: View {
191132
var body: some View {
192133
NavigationView {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import SwiftUI
2+
import SwiftUIIntrospect
3+
4+
struct ScrollViewShowcase: View {
5+
@State var firstScrollViewFound: Bool = false
6+
@State var secondScrollViewFound: Bool = false
7+
8+
var body: some View {
9+
VStack(spacing: 40) {
10+
ScrollView {
11+
Text("Default")
12+
.frame(maxWidth: .infinity)
13+
.lineLimit(1)
14+
.minimumScaleFactor(0.5)
15+
.padding(.horizontal, 12)
16+
}
17+
18+
ScrollView {
19+
Text(".introspect(.scrollView, ...)")
20+
.frame(maxWidth: .infinity)
21+
.lineLimit(1)
22+
.minimumScaleFactor(0.5)
23+
.padding(.horizontal, 12)
24+
.font(.system(.subheadline, design: .monospaced))
25+
}
26+
.background(Color(.cyan))
27+
#if os(iOS) || os(tvOS) || os(visionOS)
28+
.introspect(
29+
.scrollView,
30+
on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26)
31+
) { scrollView in
32+
scrollView.layer.backgroundColor = UIColor.cyan.cgColor
33+
scrollView.layer.cornerRadius = 12
34+
scrollView.clipsToBounds = true
35+
// scrollView.flashScrollIndicators()
36+
scrollView.bounces = false
37+
}
38+
// .modifier {
39+
// if #available(iOS 16, tvOS 16, *) {
40+
// $0.scroll
41+
// }
42+
// }
43+
#elseif os(macOS)
44+
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26)) { scrollView in
45+
scrollView.drawsBackground = true
46+
scrollView.backgroundColor = .cyan
47+
}
48+
#endif
49+
50+
ScrollView {
51+
Text(".introspect(.scrollView, ..., scope: .ancestor)")
52+
.frame(maxWidth: .infinity)
53+
.lineLimit(1)
54+
.minimumScaleFactor(0.5)
55+
.padding(.horizontal, 12)
56+
.font(.system(.subheadline, design: .monospaced))
57+
#if os(iOS) || os(tvOS) || os(visionOS)
58+
.introspect(
59+
.scrollView,
60+
on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26),
61+
scope: .ancestor
62+
) { scrollView in
63+
scrollView.layer.backgroundColor = UIColor.cyan.cgColor
64+
}
65+
#elseif os(macOS)
66+
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), scope: .ancestor) { scrollView in
67+
scrollView.drawsBackground = true
68+
scrollView.backgroundColor = .cyan
69+
}
70+
#endif
71+
}
72+
}
73+
}
74+
}

Sources/IntrospectionView.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,7 @@ final class IntrospectionPlatformViewController: PlatformViewController {
148148
super.init(nibName: nil, bundle: nil)
149149
self.handler = { [weak self] in
150150
guard let self else { return }
151-
152-
// NB: .introspect makes no guarantees about the number of times its callback is invoked,
153-
// so the below is fair play to maximize compatibility and predictability
154-
handler?(self) // we call this eagerly as most customization can successfully happen without a thread hop
155-
DispatchQueue.main.async { [weak self] in
156-
guard let self else { return }
157-
handler?(self) // we also thread hop to cover the rest of the cases where the underlying UI component isn't quite ready for customization
158-
}
151+
handler?(self)
159152
}
160153
self.isIntrospectionPlatformEntity = true
161154
IntrospectionStore.shared[id, default: .init()].controller = self

0 commit comments

Comments
 (0)