You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Swift Package that allows you to detect only one of multiple custom gestures on a single SwiftUI View.
8
8
9
-
It is internally something that customs DragGesture.
9
+
It uses [SpatialEventGesture](https://developer.apple.com/documentation/swiftui/spatialeventgesture) internally and supports multi-touch (multiple fingers).
// - Non-nil: Indicates that a gesture was detected and returns the detected gesture. The gesture detection phase is then complete and this closure will no longer be called. From then on, handleGesture will be called.
72
-
// - nil: Indicates that no gesture was detected. As long as nil is returned, it will be called when the gesture state is updated, similar to Gesture.onChanged() and Gesture.onEnded(). Unlike DragGesture, new coordinates are added and called even if they remain at the same location.
74
+
// - nil: Indicates that no gesture was detected. As long as nil is returned, it will be called when the gesture state is updated, similar to Gesture.onChanged() and Gesture.onEnded(). A heartbeat mechanism ensures continuous updates even if fingers remain at the same location.
73
75
74
76
if state.detected(.tap) { // Several default gesture detections are provided. See DefaultDetectGesture type.
75
77
// Detect tap gesture
@@ -80,8 +82,8 @@ struct ContentView: View {
80
82
} else {
81
83
// Custom: Detect circle gesture without using default gestures
// - .finished: Indicates processing is complete. Gesture processing is completely finished. The closure will no longer be called.
99
-
// - .yet: Indicates processing is incomplete. As long as .yet is returned, it will be called when the gesture state is updated, similar to Gesture.onChanged() and Gesture.onEnded(). Unlike DragGesture, new coordinates are added and called even if they remain at the same location.
101
+
// - .yet: Indicates processing is incomplete. As long as .yet is returned, it will be called when the gesture state is updated, similar to Gesture.onChanged() and Gesture.onEnded(). A heartbeat mechanism ensures continuous updates even if fingers remain at the same location.
100
102
101
103
switch detection {
102
104
case .tap:
@@ -144,23 +146,34 @@ You can access it in each handler of `View.detectGesture()`.
144
146
145
147
-`gestureValues: [DetectGestureValue]`: History of gesture information
146
148
-`detected(_:gestureValues:) -> Bool`: Whether the specified default gesture has already been detected
147
-
-`tapSplittedGestureValues: [[DetectGestureValue]]`: History of gesture information separated by tap
148
-
-`lastTapGestureValues: [DetectGestureValue]?`: GestureValues with last (or current in tapping) tap
149
-
-`lastGestureValue: DetectGestureValue?`: Last Detected Gestrue Value
149
+
-`gestureValuesAsTapSequences: [DetectGestureTapSequence]`: Gesture values converted to tap sequences
150
+
-`lastTapSequence: DetectGestureTapSequence?`: Last tap sequence
151
+
-`lastGestureValue: DetectGestureValue?`: Last detected gesture value
152
+
-`processPerSingleFingerTouch(_:)`: Process taps for each individual finger
150
153
- etc...
151
154
152
155
### DetectGestureValue
153
-
Value containing gesture state information. (like DragGesture.Value)
156
+
Value containing gesture state information.
154
157
155
-
-`dragGestureValue: DragGesture.Value`: Drag gesture value from SwiftUI
158
+
-`spatialEventCollection: SpatialEventCollection`: Spatial event collection from SwiftUI (supports multi-touch)
156
159
-`geometryProxy: GeometryProxy`: Geometry proxy for view bounds
157
-
-`timing: Timing`: Timing of this state update
158
-
-`time: Date`: Timestamp of this state (using custom Date because DragGesture.Value.time has bugs)
159
-
-`isInView() -> Bool`: Check if gesture location is within view bounds
160
+
-`timing: Timing`: Timing of this state update (`.changed`, `.ended`, or `.heartbeat`)
161
+
-`time: Date`: Timestamp of this state
162
+
-`fingerCount: Int`: Number of fingers currently touching
163
+
-`locations: [CGPoint]`: Locations of all fingers
164
+
-`isAllFingersInView() -> Bool`: Check if all fingers are within view bounds
165
+
-`asSingleFingerValues() -> [DetectGestureSingleFingerValue]`: Convert to single finger values for individual finger processing
160
166
- etc...
161
167
162
-
## Caution
163
-
- ※ Multi-Fingered Gesture has not supported yet. (No plans)
168
+
### SpatialEventCollection Extensions
169
+
170
+
Convenience properties added to [SpatialEventCollection](https://developer.apple.com/documentation/swiftui/spatialeventcollection) for easier access:
171
+
172
+
-`translation: CGSize`: Translation from start location
173
+
-`velocity: CGSize`: Velocity of the gesture movement
174
+
-`diff: CGPoint`: Distance moved from the initial tap location
175
+
176
+
For more information about SpatialEventGesture, see [Apple's official documentation](https://developer.apple.com/documentation/swiftui/spatialeventgesture).
0 commit comments