Skip to content

Commit fcf2488

Browse files
committed
wip
1 parent d4253f0 commit fcf2488

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

Sources/Introspect.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension View {
4141
/// ```
4242
public func introspect<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity>(
4343
_ viewType: SwiftUIViewType,
44-
on platforms: (PlatformViewVersions<SwiftUIViewType, PlatformSpecificEntity>)...,
44+
on platforms: (PlatformViewVersionGroup<SwiftUIViewType, PlatformSpecificEntity>)...,
4545
scope: IntrospectionScope? = nil,
4646
customize: @escaping (PlatformSpecificEntity) -> Void
4747
) -> some View {
@@ -57,12 +57,12 @@ struct IntrospectModifier<SwiftUIViewType: IntrospectableViewType, PlatformSpeci
5757

5858
init(
5959
_ viewType: SwiftUIViewType,
60-
platforms: [PlatformViewVersions<SwiftUIViewType, PlatformSpecificEntity>],
60+
platforms: [PlatformViewVersionGroup<SwiftUIViewType, PlatformSpecificEntity>],
6161
scope: IntrospectionScope?,
6262
customize: @escaping (PlatformSpecificEntity) -> Void
6363
) {
6464
self.scope = scope ?? viewType.scope
65-
if let platform = platforms.first(where: \.isCurrent) {
65+
if let platform = platforms.first(where: \.containsCurrent) {
6666
self.selector = platform.selector ?? .default
6767
} else {
6868
self.selector = nil

Sources/IntrospectionSelector.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@_spi(Internals)
21
public struct IntrospectionSelector<Target: PlatformEntity> {
32
@_spi(Internals)
43
public static var `default`: Self { .from(Target.self, selector: { $0 }) }

Sources/PlatformViewVersion.swift

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import SwiftUI
22

3-
public struct PlatformViewVersions<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> {
4-
let isCurrent: Bool
3+
public struct PlatformViewVersionGroup<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> {
4+
let containsCurrent: Bool
55
let selector: IntrospectionSelector<PlatformSpecificEntity>?
66

77
private init<Version: PlatformVersion>(
88
_ versions: [PlatformViewVersion<Version, SwiftUIViewType, PlatformSpecificEntity>]
99
) {
1010
if let currentVersion = versions.first(where: \.isCurrent) {
11-
self.isCurrent = true
11+
self.containsCurrent = true
1212
self.selector = currentVersion.selector
1313
} else {
14-
self.isCurrent = false
14+
self.containsCurrent = false
1515
self.selector = nil
1616
}
1717
}
@@ -36,14 +36,41 @@ public typealias tvOSViewVersion<SwiftUIViewType: IntrospectableViewType, Platfo
3636
public typealias macOSViewVersion<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> =
3737
PlatformViewVersion<macOSVersion, SwiftUIViewType, PlatformSpecificEntity>
3838

39-
public struct PlatformViewVersion<Version: PlatformVersion, SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> {
40-
let isCurrent: Bool
41-
let selector: IntrospectionSelector<PlatformSpecificEntity>?
39+
public enum PlatformViewVersion<Version: PlatformVersion, SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity> {
40+
case available(Version, IntrospectionSelector<PlatformSpecificEntity>?)
41+
case unavailable
42+
43+
var isCurrent: Bool {
44+
switch self {
45+
case .available(let version, _):
46+
return version.isCurrent
47+
case .unavailable:
48+
return false
49+
}
50+
}
51+
52+
var isCurrentOrPast: Bool {
53+
switch self {
54+
case .available(let version, _):
55+
return version.isCurrentOrPast
56+
case .unavailable:
57+
return false
58+
}
59+
}
60+
61+
var selector: IntrospectionSelector<PlatformSpecificEntity>? {
62+
switch self {
63+
case .available(_, let selector):
64+
return selector
65+
case .unavailable:
66+
return nil
67+
}
68+
}
4269
}
4370

4471
extension PlatformViewVersion {
4572
@_spi(Internals) public init(for version: Version, selector: IntrospectionSelector<PlatformSpecificEntity>? = nil) {
46-
self.init(isCurrent: version.isCurrent, selector: selector)
73+
self = .available(version, selector)
4774
}
4875

4976
@_spi(Internals) public static func unavailable(file: StaticString = #file, line: UInt = #line) -> Self {
@@ -60,6 +87,6 @@ extension PlatformViewVersion {
6087
https://github.com/siteline/swiftui-introspect/issues/new?title=`\(fileName):\(line)`+should+be+marked+unavailable
6188
"""
6289
)
63-
return Self(isCurrent: false, selector: nil)
90+
return .unavailable
6491
}
6592
}

0 commit comments

Comments
 (0)