// SpatialEventGesture (Official API)
SomeView()
.gesture(
SpatialEventGesture()
.onChanged { eventCollection in // : SpatialEventCollection
}
.onEnded { eventCollection in
}
)
)// detectGesture()
SomeView()
.detectGesture(
MyGesture.self,
detect: { state in // : DetectGestureState
},
handle: { state in
}
)
)SpatialEventGesture is the official API for handling multi-finger gestures (doc).
detectGesture() is a wrapper around SpatialEventGesture.
detectGesture() internally monitors SpatialEventGesture and calls detect: {} and handle: {} when onChanged or onEnded are triggered.
The new values passed (SpatialEventCollection) are wrapped in DetectGestureValue, stored in the gestureValues: [DetectGestureTouchSequence.Value] property within DetectGestureState, and passed as closure arguments.
SpatialEventCollection: Stores[SpatialEventCollection.Event], which contains gesture information for each finger at that point in time.SpatialEventCollection.Event: Information for a single finger. Each has an id, and the same finger will have the same id value.- [Note] The uniqueness of the id is only guaranteed within the same sequence. The same value may be reused in different sequences.
- [Note] onUpdated/onEnded are not called while the finger is not moving.
DetectGestureTouchSequence.Value:SpatialEventCollection+ additional custom information. See the definition for details.DetectGestureTouchSequence: A single sequence. Stores[DetectGestureTouchSequence.Value].- Unlike
SpatialEventGesture, new values are generated even while the finger is not moving, anddetect: {}andhandle: {}are called.
The DetectGestureState passed to the detectGesture() closure stores tap information in the gestureValues: [DetectGestureTouchSequence.Value] property. If it's difficult to use as-is, you can convert it to one of the following utility types.
Can be converted to [DetectGestureTouchSequence].
- Can be converted to
[DetectGestureFingerSequence]type, which organizes information by finger. - This type is convenient, so it's often converted to this type before use.
DetectGestureFingerSequence,DetectGestureFingerSequence.Finger,DetectGestureFingerSequence.Finger.Event: As shown in the diagram.
- Can be converted to
[DetectGesturePinchCollection]type for pinch gestures.
Created the ones that seem necessary.



