Skip to content

Commit 2c572aa

Browse files
committed
wip
1 parent fcf2488 commit 2c572aa

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

Sources/Introspect.swift

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ extension View {
4545
scope: IntrospectionScope? = nil,
4646
customize: @escaping (PlatformSpecificEntity) -> Void
4747
) -> some View {
48-
self.modifier(IntrospectModifier(viewType, platforms: platforms, scope: scope, customize: customize))
48+
self.modifier(IntrospectModifier(viewType, on: platforms, scope: scope, customize: customize))
49+
}
50+
51+
@_spi(Advanced)
52+
public func introspect<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity>(
53+
_ viewType: SwiftUIViewType,
54+
onOrAfter platforms: (PlatformViewVersionSingle<SwiftUIViewType, PlatformSpecificEntity>)...,
55+
scope: IntrospectionScope? = nil,
56+
customize: @escaping (PlatformSpecificEntity) -> Void
57+
) -> some View {
58+
self.modifier(IntrospectModifier(viewType, onOrAfter: platforms, scope: scope, customize: customize))
4959
}
5060
}
5161

@@ -57,7 +67,7 @@ struct IntrospectModifier<SwiftUIViewType: IntrospectableViewType, PlatformSpeci
5767

5868
init(
5969
_ viewType: SwiftUIViewType,
60-
platforms: [PlatformViewVersionGroup<SwiftUIViewType, PlatformSpecificEntity>],
70+
on platforms: [PlatformViewVersionGroup<SwiftUIViewType, PlatformSpecificEntity>],
6171
scope: IntrospectionScope?,
6272
customize: @escaping (PlatformSpecificEntity) -> Void
6373
) {
@@ -70,6 +80,21 @@ struct IntrospectModifier<SwiftUIViewType: IntrospectableViewType, PlatformSpeci
7080
self.customize = customize
7181
}
7282

83+
init(
84+
_ viewType: SwiftUIViewType,
85+
onOrAfter platforms: [PlatformViewVersionSingle<SwiftUIViewType, PlatformSpecificEntity>],
86+
scope: IntrospectionScope?,
87+
customize: @escaping (PlatformSpecificEntity) -> Void
88+
) {
89+
self.scope = scope ?? viewType.scope
90+
if let platform = platforms.first(where: \.isCurrentOrPast) {
91+
self.selector = platform.selector ?? .default
92+
} else {
93+
self.selector = nil
94+
}
95+
self.customize = customize
96+
}
97+
7398
func body(content: Content) -> some View {
7499
if let selector {
75100
content

Sources/PlatformViewVersion.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,36 @@ public struct PlatformViewVersionGroup<SwiftUIViewType: IntrospectableViewType,
2929
}
3030
}
3131

32+
@_spi(Advanced)
33+
public struct PlatformViewVersionSingle<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> {
34+
let isCurrentOrPast: Bool
35+
let selector: IntrospectionSelector<PlatformSpecificEntity>?
36+
37+
private init<Version: PlatformVersion>(
38+
_ version: PlatformViewVersion<Version, SwiftUIViewType, PlatformSpecificEntity>
39+
) {
40+
if version.isCurrentOrPast {
41+
self.isCurrentOrPast = true
42+
self.selector = version.selector
43+
} else {
44+
self.isCurrentOrPast = false
45+
self.selector = nil
46+
}
47+
}
48+
49+
public static func iOS(_ version: iOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>) -> Self {
50+
Self(version)
51+
}
52+
53+
public static func tvOS(_ version: tvOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>) -> Self {
54+
Self(version)
55+
}
56+
57+
public static func macOS(_ version: macOSViewVersion<SwiftUIViewType, PlatformSpecificEntity>) -> Self {
58+
Self(version)
59+
}
60+
}
61+
3262
public typealias iOSViewVersion<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> =
3363
PlatformViewVersion<iOSVersion, SwiftUIViewType, PlatformSpecificEntity>
3464
public typealias tvOSViewVersion<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> =

0 commit comments

Comments
 (0)