Skip to content

Commit 0de73f3

Browse files
authored
Update StyleContext API (#606)
1 parent 7f73b62 commit 0de73f3

File tree

10 files changed

+850
-28
lines changed

10 files changed

+850
-28
lines changed

Sources/OpenSwiftUICore/Event/Gesture/GestureDebug.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extension _GestureOutputs {
136136
}
137137
reallyWrap(
138138
type,
139-
kind: conformsToProtocol(type, _OpenSwiftUI_gestureModifierProtocolDescriptor()) ? .modifier : .primitive,
139+
kind: conformsToProtocol(type, _gestureModifierProtocolDescriptor()) ? .modifier : .primitive,
140140
properties: properties,
141141
inputs: inputs,
142142
data: (debugData, nil)

Sources/OpenSwiftUICore/Event/Gesture/GestureDescriptor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package struct GestureDescriptor: TupleDescriptor {
1212
package static var typeCache: [ObjectIdentifier: TupleTypeDescription<GestureDescriptor>] = [:]
1313

1414
package static var descriptor: UnsafeRawPointer {
15-
_OpenSwiftUI_gestureProtocolDescriptor()
15+
_gestureProtocolDescriptor()
1616
}
1717
}
1818

@@ -22,6 +22,6 @@ package struct GestureModifierDescriptor: TupleDescriptor {
2222
package static var typeCache: [ObjectIdentifier: TupleTypeDescription<GestureModifierDescriptor>] = [:]
2323

2424
package static var descriptor: UnsafeRawPointer {
25-
_OpenSwiftUI_gestureModifierProtocolDescriptor()
25+
_gestureModifierProtocolDescriptor()
2626
}
2727
}

Sources/OpenSwiftUI/View/Configuration/StaticIf.swift renamed to Sources/OpenSwiftUICore/View/Configuration/StaticIf.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
//
22
// StaticIf.swift
3-
// OpenSwiftUI
3+
// OpenSwiftUICore
44
//
5-
// Audited for 6.0.87
5+
// Audited for 6.5.4
66
// Status: Complete
77

8-
import OpenSwiftUICore
9-
108
/// A container view that conditionally renders one of two views based on a `ViewInputPredicate`.
119
///
1210
/// `StaticIf` makes view selection decisions based on the evaluation of a `ViewInputPredicate`
@@ -228,7 +226,23 @@ extension ViewModifier {
228226
///
229227
/// - Parameter predicate: The predicate type used to evaluate against view inputs.
230228
/// - Returns: A conditional modifier that applies the current modifier only when the predicate is true.
231-
package func requiring<Predicate>(_ predicate: Predicate.Type) -> StaticIf<Predicate, Self, EmptyModifier> where Predicate: ViewInputPredicate {
229+
package func requiring<Predicate>(
230+
_ predicate: Predicate.Type
231+
) -> StaticIf<
232+
Predicate,
233+
Self,
234+
EmptyModifier
235+
> where Predicate: ViewInputPredicate {
232236
StaticIf(predicate, then: self)
233237
}
238+
239+
package func requiring<each Q>(
240+
_ queries: repeat (each Q).Type
241+
) -> StaticIf<
242+
StyleContextAcceptsPredicate<(repeat each Q)>,
243+
Self,
244+
EmptyModifier
245+
> where repeat each Q: StyleContext {
246+
StaticIf(StyleContextAcceptsPredicate<(repeat each Q)>.self, then: self)
247+
}
234248
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// AnyStyleContext.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for 6.5.4
6+
// Status: Complete
7+
// ID: 95C35B9B1549B6F41E131C274C6E343F (SwiftUICore)
8+
9+
// MARK: - AnyStyleContextType
10+
11+
package struct AnyStyleContextType: Equatable {
12+
private let base: any AnyStyleContextTypeBox.Type
13+
14+
private init(base: any AnyStyleContextTypeBox.Type) {
15+
self.base = base
16+
}
17+
18+
package init<C>(_ context: C.Type = C.self) where C: StyleContext {
19+
base = StyleContextTypeBox<C>.self
20+
}
21+
22+
package static func == (lhs: AnyStyleContextType, rhs: AnyStyleContextType) -> Bool {
23+
lhs.base.isEqual(to: rhs.base)
24+
}
25+
26+
package func acceptsTop<Q>(_ query: Q.Type) -> Bool {
27+
base.acceptsTop(query)
28+
}
29+
30+
package func pushing<N>(_ newContext: N.Type) -> AnyStyleContextType where N: StyleContext {
31+
AnyStyleContextType(base: base.pushing(newContext))
32+
}
33+
34+
package func acceptsAny<each Q>(_ queries: repeat (each Q).Type) -> Bool where repeat each Q: StyleContext {
35+
base.acceptsAny(repeat each queries)
36+
}
37+
}
38+
39+
// MARK: - AnyStyleContextTypeBox
40+
41+
private protocol AnyStyleContextTypeBox {
42+
static func isEqual(to other: AnyStyleContextTypeBox.Type) -> Bool
43+
44+
static func acceptsTop<Q>(_ query: Q.Type) -> Bool
45+
46+
static func acceptsAny<each Q>(_ queries: repeat (each Q).Type) -> Bool where repeat each Q: StyleContext
47+
48+
static func pushing<N>(_ newContext: N.Type) -> AnyStyleContextTypeBox.Type where N: StyleContext
49+
}
50+
51+
// MARK: - StyleContextTypeBox
52+
53+
private struct StyleContextTypeBox<Context>: AnyStyleContextTypeBox where Context: StyleContext {
54+
static func isEqual(to other: AnyStyleContextTypeBox.Type) -> Bool {
55+
other is StyleContextTypeBox<Context>.Type
56+
}
57+
58+
static func acceptsTop<Q>(_ query: Q.Type) -> Bool {
59+
Context.acceptsTop(query)
60+
}
61+
62+
static func acceptsAny<each Q>(_ queries: repeat (each Q).Type) -> Bool where repeat each Q: StyleContext {
63+
Context.acceptsAny(repeat each queries)
64+
}
65+
66+
static func pushing<N>(_ newContext: N.Type) -> AnyStyleContextTypeBox.Type where N: StyleContext {
67+
StyleContextTypeBox<TupleStyleContext<(N, Context)>>.self
68+
}
69+
}

0 commit comments

Comments
 (0)