Gestures
The Scripting app provides a gesture system similar to SwiftUI, allowing any view (<VStack>, <HStack>, <Text>, etc.) to respond to touch interactions such as tapping, long pressing, dragging, rotating, and magnifying.
Dedicated keyboard surfaces can also use onTouchGesture on iOS 18+ for per-finger UIKit phases. This separate API does not accept GestureMask or change existing DragGesture. Read its cancellation, velocity/prediction and multitouch migration rules first.
You can use:
- Simplified gesture properties like
onTapGesture,onLongPressGesture,onDragGesture, or - Advanced gesture objects such as
TapGesture(),LongPressGesture(), and thegesturemodifiers for composition and priority control.
1. Simple Gesture Properties
These are convenient, shorthand ways to add gestures directly to a view.
onTapGesture
Executes an action when a tap gesture is recognized.
Type
Parameters
Examples
onLongPressGesture
Executes an action when a long press gesture is recognized.
Type
Parameters
Examples
onDragGesture
Adds a drag gesture to a view, tracking position, offset, and velocity.
Type
Parameters
DragGestureDetails
Example
2. Gesture Classes (Advanced Usage)
For complex interaction handling or gesture composition, use the gesture constructors and modifiers.
GestureInfo Class
All gesture constructors return a GestureInfo object that defines configuration and callbacks.
Example
TapGesture
Detects single or multiple taps.
Example
LongPressGesture
Detects press and hold gestures.
Example
DragGesture
Tracks finger or pointer movement.
Example
MagnifyGesture
Detects pinch zoom gestures.
Example
RotateGesture
Detects rotation gestures.
Example
3. Gesture Modifiers for Views
All views support the following gesture-related properties.
gesture
Adds a gesture to the view.
highPriorityGesture
Adds a gesture with higher priority than existing ones on the view.
simultaneousGesture
Allows multiple gestures to be recognized simultaneously.
defersSystemGestures
Gives your custom gestures precedence over system gestures originating from screen edges.
Accepted Values
4. GestureMask
Controls how adding a gesture affects other gestures on the same view or its subviews.
Example
5. Summary Table
Input source filtering (iOS 27.0+)
GestureInputKinds accepts "all" or an array of "directTouch", "indirectTouch", "pencil", and "pointer". Omitted means all sources; an empty array accepts none. Earlier systems ignore the filter and preserve existing gesture behavior.
Set inputKinds in the object forms of onTapGesture, onLongPressGesture, and onDragGesture. The object form of onTapGesture.perform receives { x, y } in the requested coordinate space; the function shorthand still takes no arguments. count defaults to 1.
TapGesture accepts its existing numeric count or { count?, inputKinds? }. DragGesture and LongPressGesture accept inputKinds in their existing options. RotateGesture(minAngleDelta?, inputKinds?) and MagnifyGesture(minScaleDelta?, inputKinds?) add an optional second parameter and retain the old calling forms. The filter also applies when these gesture objects are used with gesture, simultaneousGesture, or highPriorityGesture.
Input source types
Device hinge changes (iOS 27.1+)
onHingeChange accepts (oldContext, newContext) => void or { isEnabled?: boolean, action: (oldContext, newContext) => void }. isEnabled defaults to true; false disables observation. Both direct props and fluent modifiers are supported. Earlier systems ignore the modifier.
Each DeviceHingeContext has hinge: null | { status, angle }. status is closed, partiallyOpen, fullyOpen or unknown; angle contains degrees and radians. A null hinge means hinge information is unavailable, including devices without a hinge. The callback reports changes, rather than guaranteeing an initial event. Observation requires an active rendered script view; it is not a background monitoring API. Widgets and Live Activities do not provide continuous JavaScript hinge observation.
Use this for optional layout adaptation. Do not make common tasks depend on a particular hinge angle; provide accessible controls and a usable layout when hinge is null. Avoid frequent VoiceOver announcements or focus changes for continuously changing angles.
