|
2 | 2 | // Gesture.swift |
3 | 3 | // OpenSwiftUICore |
4 | 4 | // |
5 | | -// Status: WIP |
| 5 | +// Status: Complete |
6 | 6 | // ID: 5DF390A778F4D193C5F92C06542566B0 (SwiftUICore) |
7 | 7 |
|
8 | | -package import OpenGraphShims |
9 | | -import OpenSwiftUI_SPI |
10 | | - |
11 | 8 | // MARK: - Gesture [6.5.4] |
12 | 9 |
|
13 | 10 | /// An instance that matches a sequence of events to a gesture, and returns a |
@@ -103,272 +100,3 @@ extension Gesture where Value == Body.Value { |
103 | 100 | return Body.makeDebuggableGesture(gesture: body, inputs: inputs) |
104 | 101 | } |
105 | 102 | } |
106 | | - |
107 | | -// MARK: - GestureInputs [6.5.4] [WIP] |
108 | | - |
109 | | -/// Input (aka inherited) attributes for gesture objects. |
110 | | -@available(OpenSwiftUI_v1_0, *) |
111 | | -public struct _GestureInputs { |
112 | | - package var viewInputs: _ViewInputs |
113 | | - |
114 | | - package var viewSubgraph: Subgraph |
115 | | - |
116 | | - package var preferences: PreferencesInputs |
117 | | - |
118 | | - package var events: Attribute<[EventID : any EventType]> |
119 | | - |
120 | | - package var resetSeed: Attribute<UInt32> |
121 | | - |
122 | | - @_spi(ForOpenSwiftUIOnly) |
123 | | - public struct InheritedPhase: OptionSet, Defaultable { |
124 | | - public let rawValue: Int |
125 | | - |
126 | | - public init(rawValue: Int) { |
127 | | - self.rawValue = rawValue |
128 | | - } |
129 | | - |
130 | | - package static let failed: _GestureInputs.InheritedPhase = .init(rawValue: 1 << 0) |
131 | | - |
132 | | - package static let active: _GestureInputs.InheritedPhase = .init(rawValue: 1 << 1) |
133 | | - |
134 | | - package static let defaultValue: _GestureInputs.InheritedPhase = .failed |
135 | | - } |
136 | | - |
137 | | - package var inheritedPhase: Attribute<_GestureInputs.InheritedPhase> |
138 | | - |
139 | | - package var failedPhase: Attribute<GesturePhase<Void>> { |
140 | | - get { preconditionFailure("TODO") } |
141 | | - } |
142 | | - |
143 | | - package var options: _GestureInputs.Options |
144 | | - |
145 | | - package var platformInputs: PlatformGestureInputs |
146 | | - |
147 | | - package init( |
148 | | - _ inputs: _ViewInputs, |
149 | | - viewSubgraph: Subgraph, |
150 | | - events: Attribute<[EventID : any EventType]>, |
151 | | - time: Attribute<Time>, |
152 | | - resetSeed: Attribute<UInt32>, |
153 | | - inheritedPhase: Attribute<_GestureInputs.InheritedPhase>, |
154 | | - gesturePreferenceKeys: Attribute<PreferenceKeys> |
155 | | - ) { |
156 | | - |
157 | | - preconditionFailure("TODO") |
158 | | - } |
159 | | - |
160 | | - package mutating func mergeViewInputs( |
161 | | - _ other: _ViewInputs, |
162 | | - viewSubgraph: Subgraph |
163 | | - ) { |
164 | | - preconditionFailure("TODO") |
165 | | - } |
166 | | - |
167 | | - package func animatedPosition() -> Attribute<ViewOrigin> { |
168 | | - viewSubgraph.apply { |
169 | | - viewInputs.animatedPosition() |
170 | | - } |
171 | | - } |
172 | | - |
173 | | - package func intern<T>( |
174 | | - _ value: T, |
175 | | - id: GraphHost.ConstantID |
176 | | - ) -> Attribute<T> { |
177 | | - GraphHost.currentHost.intern(value, id: id) |
178 | | - } |
179 | | - |
180 | | - package func makeIndirectOutputs<Value>() -> _GestureOutputs<Value> { |
181 | | - preconditionFailure("TODO") |
182 | | - } |
183 | | - |
184 | | - package func makeDefaultOutputs<Value>() -> _GestureOutputs<Value> { |
185 | | - preconditionFailure("TODO") |
186 | | - } |
187 | | -} |
188 | | - |
189 | | -extension _GestureInputs { |
190 | | - package struct Options: OptionSet { |
191 | | - package let rawValue: UInt32 |
192 | | - |
193 | | - @inlinable |
194 | | - package init(rawValue: UInt32) { |
195 | | - self.rawValue = rawValue |
196 | | - } |
197 | | - |
198 | | - @inlinable |
199 | | - package static var preconvertedEventLocations: _GestureInputs.Options { |
200 | | - .init(rawValue: 1 << 0) |
201 | | - } |
202 | | - |
203 | | - @inlinable |
204 | | - package static var allowsIncompleteEventSequences: _GestureInputs.Options { |
205 | | - .init(rawValue: 1 << 1) |
206 | | - } |
207 | | - |
208 | | - @inlinable |
209 | | - package static var skipCombiners: _GestureInputs.Options { |
210 | | - .init(rawValue: 1 << 2) |
211 | | - } |
212 | | - |
213 | | - @inlinable |
214 | | - package static var includeDebugOutput: _GestureInputs.Options { |
215 | | - .init(rawValue: 1 << 3) |
216 | | - } |
217 | | - |
218 | | - @inlinable |
219 | | - package static var gestureGraph: _GestureInputs.Options { |
220 | | - .init(rawValue: 1 << 4) |
221 | | - } |
222 | | - } |
223 | | -} |
224 | | - |
225 | | -@available(*, unavailable) |
226 | | -extension _GestureInputs: Sendable {} |
227 | | - |
228 | | -@available(*, unavailable) |
229 | | -extension _GestureInputs.InheritedPhase: Sendable {} |
230 | | - |
231 | | -// MARK: - GestureOutputs [6.5.4] |
232 | | - |
233 | | -/// Output (aka synthesized) attributes for gesture objects. |
234 | | -@available(OpenSwiftUI_v1_0, *) |
235 | | -public struct _GestureOutputs<Value> { |
236 | | - package var phase: Attribute<GesturePhase<Value>> |
237 | | - |
238 | | - private var _debugData: OptionalAttribute<GestureDebug.Data> |
239 | | - |
240 | | - package var preferences: PreferencesOutputs |
241 | | - |
242 | | - package var debugData: Attribute<GestureDebug.Data>? { |
243 | | - get { _debugData.attribute } |
244 | | - set { _debugData.attribute = newValue } |
245 | | - } |
246 | | - |
247 | | - package init(phase: Attribute<GesturePhase<Value>>) { |
248 | | - self.phase = phase |
249 | | - self._debugData = .init() |
250 | | - self.preferences = .init() |
251 | | - } |
252 | | - |
253 | | - package func withPhase<T>(_ phase: Attribute<GesturePhase<T>>) -> _GestureOutputs<T> { |
254 | | - var outputs = _GestureOutputs<T>(phase: phase) |
255 | | - outputs._debugData = _debugData |
256 | | - outputs.preferences = preferences |
257 | | - return outputs |
258 | | - } |
259 | | - |
260 | | - package func overrideDefaultValues(_ childOutputs: _GestureOutputs<Value>) { |
261 | | - phase.overrideDefaultValue(childOutputs.phase, type: GesturePhase<Value>.self) |
262 | | - if let debugData, let childDebugData = childOutputs.debugData { |
263 | | - debugData.overrideDefaultValue(childDebugData, type: GestureDebug.Data.self) |
264 | | - } |
265 | | - preferences.attachIndirectOutputs(to: childOutputs.preferences) |
266 | | - } |
267 | | - |
268 | | - package func setIndirectDependency(_ dependency: AnyAttribute?) { |
269 | | - phase.identifier.indirectDependency = dependency |
270 | | - if let debugData { |
271 | | - debugData.identifier.indirectDependency = dependency |
272 | | - } |
273 | | - preferences.setIndirectDependency(dependency) |
274 | | - } |
275 | | - |
276 | | - package func attachIndirectOutputs(_ childOutputs: _GestureOutputs<Value>) { |
277 | | - phase.identifier.source = childOutputs.phase.identifier |
278 | | - if let debugData, let childDebugData = childOutputs.debugData { |
279 | | - debugData.identifier.source = childDebugData.identifier |
280 | | - } |
281 | | - preferences.attachIndirectOutputs(to: childOutputs.preferences) |
282 | | - } |
283 | | - |
284 | | - package func detachIndirectOutputs() { |
285 | | - phase.identifier.source = .nil |
286 | | - if let debugData { |
287 | | - debugData.identifier.source = .nil |
288 | | - } |
289 | | - preferences.detachIndirectOutputs() |
290 | | - } |
291 | | - |
292 | | - package subscript(anyKey key: any PreferenceKey.Type) -> AnyAttribute? { |
293 | | - get { preferences[anyKey: key] } |
294 | | - set { preferences[anyKey: key] = newValue } |
295 | | - } |
296 | | - |
297 | | - package subscript<K>(key: K.Type) -> Attribute<K.Value>? where K: PreferenceKey { |
298 | | - get { preferences[key] } |
299 | | - set { preferences[key] = newValue } |
300 | | - } |
301 | | - |
302 | | - package mutating func appendPreference<K>( |
303 | | - key: K.Type, |
304 | | - value: Attribute<K.Value> |
305 | | - ) where K: PreferenceKey { |
306 | | - preferences.appendPreference(key: key, value: value) |
307 | | - } |
308 | | - |
309 | | - package func forEachPreference(_ body: (any PreferenceKey.Type, AnyAttribute) -> Void) { |
310 | | - preferences.forEachPreference(body) |
311 | | - } |
312 | | -} |
313 | | - |
314 | | -// MARK: - GestureCategory [6.5.4] |
315 | | - |
316 | | -@_spi(ForOpenSwiftUIOnly) |
317 | | -@available(OpenSwiftUI_v6_0, *) |
318 | | -public struct GestureCategory: OptionSet { |
319 | | - public let rawValue: Int |
320 | | - |
321 | | - public init(rawValue: Int) { |
322 | | - self.rawValue = rawValue |
323 | | - } |
324 | | - |
325 | | - package static let magnify: GestureCategory = .init(rawValue: 1 << 0) |
326 | | - |
327 | | - package static let rotate: GestureCategory = .init(rawValue: 1 << 1) |
328 | | - |
329 | | - package static let drag: GestureCategory = .init(rawValue: 1 << 2) |
330 | | - |
331 | | - package static let select: GestureCategory = .init(rawValue: 1 << 3) |
332 | | - |
333 | | - package static let longPress: GestureCategory = .init(rawValue: 1 << 4) |
334 | | - |
335 | | - package struct Key: PreferenceKey { |
336 | | - package static let _includesRemovedValues: Bool = true |
337 | | - |
338 | | - package static let defaultValue: GestureCategory = .defaultValue |
339 | | - |
340 | | - package static func reduce( |
341 | | - value: inout GestureCategory.Key.Value, |
342 | | - nextValue: () -> GestureCategory.Key.Value |
343 | | - ) { |
344 | | - value = GestureCategory(rawValue: value.rawValue | nextValue().rawValue) |
345 | | - } |
346 | | - } |
347 | | -} |
348 | | - |
349 | | -@available(*, unavailable) |
350 | | -extension GestureCategory: Sendable {} |
351 | | - |
352 | | -// MARK: - GestureDescriptor [6.5.4] |
353 | | - |
354 | | -package struct GestureDescriptor: TupleDescriptor { |
355 | | - package static var typeCache: [ObjectIdentifier: TupleTypeDescription<GestureDescriptor>] = [:] |
356 | | - |
357 | | - package static var descriptor: UnsafeRawPointer { |
358 | | - _OpenSwiftUI_gestureProtocolDescriptor() |
359 | | - } |
360 | | -} |
361 | | - |
362 | | -// MARK: - GestureModifierDescriptor [6.5.4] |
363 | | - |
364 | | -package struct GestureModifierDescriptor: TupleDescriptor { |
365 | | - package static var typeCache: [ObjectIdentifier: TupleTypeDescription<GestureModifierDescriptor>] = [:] |
366 | | - |
367 | | - package static var descriptor: UnsafeRawPointer { |
368 | | - _OpenSwiftUI_gestureModifierProtocolDescriptor() |
369 | | - } |
370 | | -} |
371 | | - |
372 | | -// MARK: - PlatformGestureInputs [6.5.4] |
373 | | - |
374 | | -package struct PlatformGestureInputs {} |
0 commit comments