Skip to content

Commit ea28c40

Browse files
authored
Add Core types: GesturePhase, GestureOutput, UpdateScheduler (#8)
1 parent 13351fe commit ea28c40

15 files changed

Lines changed: 729 additions & 307 deletions

Package.resolved

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ let libraryEvolutionCondition = envBoolValue("LIBRARY_EVOLUTION", default: build
137137
let compatibilityTestCondition = envBoolValue("COMPATIBILITY_TEST", default: false)
138138

139139
let gesturesCondition = envBoolValue("OPENGESTURESSHIMS_GESTURES", default: false)
140-
let useLocalDeps = envBoolValue("USE_LOCAL_DEPS")
140+
let useLocalDeps = envBoolValue("USE_LOCAL_DEPS", default: false)
141141

142142
let swiftCorelibsPath = envStringValue("LIB_SWIFT_PATH") ?? "\(Context.packageDirectory)/Sources/SwiftCorelibs/include"
143143

@@ -225,6 +225,9 @@ let openGesturesShimsTarget = Target.target(
225225

226226
let openGesturesCompatibilityTestsTarget = Target.testTarget(
227227
name: "OpenGesturesCompatibilityTests",
228+
dependencies: [
229+
.product(name: "OpenAttributeGraphShims", package: "OpenAttributeGraph"),
230+
],
228231
swiftSettings: sharedSwiftSettings
229232
)
230233

@@ -237,6 +240,7 @@ let package = Package(
237240
],
238241
dependencies: [
239242
.package(url: "https://github.com/OpenSwiftUIProject/OpenCoreGraphics.git", branch: "main"),
243+
.package(url: "https://github.com/OpenSwiftUIProject/OpenAttributeGraph.git", branch: "main"),
240244
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.0"),
241245
],
242246
targets: [

Sources/OpenGestures/Component/GestureComponentController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public final class GestureComponentController<C: GestureComponent>: AnyGestureCo
5959
break
6060
case .value(let value, _):
6161
try node.update(someValue: value, isFinalUpdate: false)
62-
case .final(let value, _):
62+
case .finalValue(let value, _):
6363
try node.update(someValue: value, isFinalUpdate: true)
6464
}
6565
} catch {
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
//
2+
// GestureOutput.swift
3+
// OpenGestures
4+
//
5+
// Audited for 9126.1.5
6+
// Status: Complete
7+
8+
// MARK: - GestureOutput
9+
10+
public enum GestureOutput<Value: Sendable>: Sendable {
11+
case empty(GestureOutputEmptyReason, metadata: GestureOutputMetadata?)
12+
case value(Value, metadata: GestureOutputMetadata?)
13+
case finalValue(Value, metadata: GestureOutputMetadata?)
14+
}
15+
16+
extension GestureOutput {
17+
public var value: Value? {
18+
switch self {
19+
case let .value(v, _): v
20+
case let .finalValue(v, _): v
21+
case .empty: nil
22+
}
23+
}
24+
25+
public var isEmpty: Bool {
26+
switch self {
27+
case .empty: true
28+
default: false
29+
}
30+
}
31+
32+
public var isFinal: Bool {
33+
switch self {
34+
case .finalValue: true
35+
default: false
36+
}
37+
}
38+
}
39+
40+
// MARK: - GestureOutput + NestedCustomStringConvertible
41+
42+
extension GestureOutput: NestedCustomStringConvertible {
43+
package func populateNestedDescription(_ nested: inout NestedDescription) {
44+
let metadata: GestureOutputMetadata?
45+
switch self {
46+
case let .empty(reason, m):
47+
nested.append(reason, label: "emptyReason")
48+
metadata = m
49+
case let .value(v, m):
50+
nested.append(v, label: "value")
51+
metadata = m
52+
case let .finalValue(v, m):
53+
nested.append(v, label: "finalValue")
54+
metadata = m
55+
}
56+
if let metadata {
57+
nested.append(metadata, label: "metadata")
58+
}
59+
}
60+
}
61+
62+
// MARK: - GestureOutputEmptyReason
63+
64+
public enum GestureOutputEmptyReason: Hashable, Sendable {
65+
case noData
66+
case filtered
67+
case timeUpdate
68+
}
69+
70+
// MARK: - GestureOutputMetadata
71+
72+
public struct GestureOutputMetadata: Sendable {
73+
package var updatesToSchedule: [UpdateRequest]
74+
package var updatesToCancel: [UpdateRequest]
75+
package var traceAnnotation: UpdateTraceAnnotation?
76+
77+
package init(
78+
updatesToSchedule: [UpdateRequest] = [],
79+
updatesToCancel: [UpdateRequest] = [],
80+
traceAnnotation: UpdateTraceAnnotation? = nil
81+
) {
82+
self.updatesToSchedule = updatesToSchedule
83+
self.updatesToCancel = updatesToCancel
84+
self.traceAnnotation = traceAnnotation
85+
}
86+
}
87+
88+
// MARK: - GestureOutputMetadata + NestedCustomStringConvertible
89+
90+
extension GestureOutputMetadata: NestedCustomStringConvertible {
91+
package func populateNestedDescription(_ nested: inout NestedDescription) {
92+
nested.options.formUnion([.hideTypeName, .compact])
93+
nested.customPrefix = ""
94+
nested.customSuffix = ""
95+
if !updatesToSchedule.isEmpty {
96+
nested.append("\(updatesToSchedule)", label: "updatesToSchedule")
97+
}
98+
if !updatesToCancel.isEmpty {
99+
nested.append("\(updatesToCancel)", label: "updatesToCancel")
100+
}
101+
if let traceAnnotation {
102+
nested.append(traceAnnotation.value, label: "traceAnnotation")
103+
}
104+
}
105+
}
106+
107+
// MARK: - UpdateTraceAnnotation
108+
109+
package struct UpdateTraceAnnotation: Sendable {
110+
public var value: String
111+
112+
public init(value: String) {
113+
self.value = value
114+
}
115+
}
116+
117+
// MARK: - GestureOutputStatusCombiner
118+
119+
package struct GestureOutputStatusCombiner: Sendable {
120+
package var combine: @Sendable ([GestureOutputStatus]) throws -> GestureOutputStatus
121+
122+
package init(combine: @escaping @Sendable ([GestureOutputStatus]) throws -> GestureOutputStatus) {
123+
self.combine = combine
124+
}
125+
}
126+
127+
// MARK: - GestureOutputStatus
128+
129+
package enum GestureOutputStatus: Hashable, Sendable {
130+
case empty
131+
case value
132+
case finalValue
133+
}
134+
135+
// MARK: - GestureOutputArrayCombiner
136+
137+
package struct GestureOutputArrayCombiner<A: Sendable>: Sendable {
138+
package let statusCombiner: GestureOutputStatusCombiner
139+
140+
package init(statusCombiner: GestureOutputStatusCombiner) {
141+
self.statusCombiner = statusCombiner
142+
}
143+
}
144+
145+
// MARK: - GestureOutputCombiner
146+
147+
package struct GestureOutputCombiner<each A: Sendable, B: Sendable>: Sendable {
148+
package let combineValues: (@Sendable (repeat each A) throws -> B)?
149+
package let combineOptionals: (@Sendable (repeat (each A)?) throws -> B)?
150+
package let statusCombiner: GestureOutputStatusCombiner
151+
152+
package init(
153+
combineValues: (@Sendable (repeat each A) throws -> B)?,
154+
combineOptionals: (@Sendable (repeat (each A)?) throws -> B)?,
155+
statusCombiner: GestureOutputStatusCombiner
156+
) {
157+
self.combineValues = combineValues
158+
self.combineOptionals = combineOptionals
159+
self.statusCombiner = statusCombiner
160+
}
161+
}

0 commit comments

Comments
 (0)