onLongPressGesture
Adds a long press gesture recognizer.
onLongPressGesture(handler, minimumDuration)
| Parameter | Type | Description |
|---|---|---|
handler | () => void | Function to call when long pressed. |
minimumDuration(optional) | number | Minimum duration for long press (default: 0.5s) |
Adds a long press gesture recognizer.
Returns: ModifierConfig
Works with
You can add onLongPressGesture to any view. It changes what you see on 31 of the 39 components.
Needs care
It works on these components, but not in the way that you may expect.
| Component | What to know |
|---|---|
| VStack | Touches on the empty space between children are not detected. Add contentShape('rectangle') before this modifier. |
| HStack | Touches on the empty space between children are not detected. Add contentShape('rectangle') before this modifier. |
| ZStack | Touches on the empty space between children are not detected. Add contentShape('rectangle') before this modifier. |
| LazyVStack | Touches on the empty space between children are not detected. Add contentShape('rectangle') before this modifier. |
| LazyHStack | Touches on the empty space between children are not detected. Add contentShape('rectangle') before this modifier. |
| ScrollView | Put the handler on a child view. A gesture on the scroll view itself can stop the scroll. |
No visible effect
These components accept it, but you see no change.
| Component | Why nothing happens |
|---|---|
| Spacer | In SDK 57, Spacer does not send modifier events to JavaScript, so the handler does not run. |
| Divider | In SDK 57, Divider does not send modifier events to JavaScript, so the handler does not run. |
| Slider | In SDK 57, Slider does not send modifier events to JavaScript, so the handler does not run. |
| Menu | In SDK 57, Menu does not send modifier events to JavaScript, so the handler does not run. |
| ContextMenu | In SDK 57, ContextMenu does not send modifier events to JavaScript, so the handler does not run. |
| ProgressView | In SDK 57, ProgressView does not send modifier events to JavaScript, so the handler does not run. |
| Gauge | In SDK 57, Gauge does not send modifier events to JavaScript, so the handler does not run. |
| AccessoryWidgetBackground | In SDK 57, AccessoryWidgetBackground does not send modifier events to JavaScript, so the handler does not run. |
Sources
The original Expo docs for this page:
- onLongPressGesture (Modifiers) (
source-of-truth/versions/v57.0.0/sdk/ui/swift-ui/modifiers.md)
onGeometryChange
Calls the handler whenever the view's geometry changes, with its position and size. x and y are in the global coordinate space (relative to the window); all values are in points.
onScrollPhaseChange
Fires when SwiftUI's scroll phase changes (e.g., the user begins dragging, the scroll view starts decelerating, or scrolling settles to idle). The second argument is the scroll geometry sampled at the phase transition, useful for reading the final offset on settle without subscribing to per-frame onScrollGeometryChange.