React Native · Components
GestureView
Gesture region: a drag inside it does not conflict with scrolling.
Import
GestureView
componentGesture region: a drag inside it does not conflict with scrolling.
When a finger lands on this view, the ScrollView/FlatList above waits until the direction is known (slop, 8 dp). If the move is in a direction the region wants, the scroll does not start at all for that touch; otherwise the scroll starts at once with the accumulated movement. The decision is made on the native side (iOS UIGestureRecognizer, the Android touch intercept chain) in the same frame as the touch; it behaves the same on both platforms. It also registers with the arbiter in JS: outer JS drags (the navigator's back gesture, Sheet) yield to this region's directions.
Without the native view (web, an old build) a plain View is drawn; the behavior continues with the JS arbiter.
Examples
toDirections
functionTurns a GestureClaim value into a set of directions.
directionOf
functionDominant direction of the movement (dx, dy the finger's displacement).
gestureArbiter
moduleThe arbiter. Components mostly use it indirectly (GestureView, usePanGesture, ScrollView); an outer drag that writes its own PanResponder (e.g. a drawer pulled from the edge) should ask with yields before taking a move.
| Name | Type | Description |
|---|---|---|
enter | (region: GestureRegion, event: ArbiterTouchEvent): void | A region registers when the finger lands on it (onTouchStart). A new touch (one finger, a different event object) clears the previous list. |
leave | (region: GestureRegion): void | The region leaves the touch (the finger lifted or the touch was cancelled). |
regions | (): readonly GestureRegion[] | Regions under the touch (innermost first). |
claimant | (direction: GestureDirection, query?: GestureClaimQuery): GestureRegion | undefined | The innermost region that wants a move in this direction. If a region is found, an outer handler must not take the move. |
yields | (direction: GestureDirection, query?: GestureClaimQuery): boolean | Whether a region inside wants this direction (gestureArbiter.claimant). |
begin | (region: GestureRegion): void | The region took the move (a drag or scroll started). |
end | (region: GestureRegion): void | The region's move ended. |
isActive | (kind?: GestureRegionKind): boolean | Whether some region is handling a move right now (optionally by kind). |
subscribe | (listener: (event: GestureArbiterEvent) => void): () => void | Listens to begin/end events; returns a function that stops listening. |
Examples
hasNativeGesture
functionWhether the native gesture view (YasinGestureView) exists in this build. If not (web, an app whose native code was not rebuilt), regions are drawn as plain Views; the JS arbiter still works, and the scroll above is disabled from JS when a drag starts (one frame late).
usePanGesture
functionA drag that does not conflict with scrolling. Built on top of PanResponder and used with GestureView:
- Starts only for moves in the
claimdirections; a horizontal drag on a vertically scrolling page does not move the page, and a vertical move does not start the drag. - On the native side (the same on iOS and Android) the decision is made on the UI thread: the scroll does not "escape" because of JS latency.
- Yields to an inner region that wants the same direction (a nested drag or a scrollable horizontal list).
- Once started it does not hand over to another handler (the navigator's back gesture, Sheet).
Examples
GestureDirection
typeDirection of the finger's movement.
GestureClaim
typeDirections a region takes: "horizontal" (left + right), "vertical" (up + down), "all", "none" or a list of directions (e.g. ["right"] for a "reply" that is only pulled to the right).
GestureDirections
interfaceOn/off state of the directions.
| Name | Type | Description |
|---|---|---|
left | boolean | Can move left. |
right | boolean | Can move right. |
up | boolean | Can move up. |
down | boolean | Can move down. |
Kind of region: a gesture handling a drag, or a scroll view.
GestureRegion
interfaceA region registered with the arbiter.
| Name | Type | Description |
|---|---|---|
id | number | Unique id. |
kind | GestureRegionKind | Kind of the region. |
claims | (direction: GestureDirection): boolean | Whether it wants a move in this direction right now (e.g. if the scroll is not at the edge). |
GestureArbiterEvent
interfaceEvent emitted by the arbiter.
| Name | Type | Description |
|---|---|---|
type | "begin" | "end" | begin: the region took the move (a drag or scroll started); end: it finished. |
region | GestureRegion | Region the event belongs to. |
GestureClaimQuery
interfaceOptions of gestureArbiter.claimant.
| Name | Type | Description |
|---|---|---|
below? | GestureRegion | Only regions INSIDE this region are considered (a region yields to what is inside it, not outside). If omitted, all regions under the touch. |
kinds? | readonly GestureRegionKind[] | Only regions of this kind. If omitted, all. |
ArbiterTouchEvent
interfaceThe part of a touch event the arbiter uses.
| Name | Type | Description |
|---|---|---|
nativeEvent | { readonly touches?: ArrayLike<unknown>; } | Native touch event; only the touch count is read. |
GestureViewProps
interfaceProps of GestureView.
Extends: ViewProps
| Name | Type | Default | Description |
|---|---|---|---|
ref? | Ref<ViewRef> | Ref of the underlying native view. | |
gesture? | PanGesture | A usePanGesture result. When given, the directions and handlers are taken from it; claim, claimOnStart, claimPinch, slop, enabled are ignored. | |
claim? | GestureClaim | "none" | For components using their own PanResponder: directions this region takes. A drag in those directions does not start the scroll above. |
claimOnStart? | boolean | false | Takes the touch as soon as it lands. If it becomes true while a touch is in progress (e.g. a drag starting with a long press), scroll views above release that touch at once. |
claimPinch? | boolean | false | Takes it when a second finger lands. |
slop? | number | 8 | Distance at which the direction is decided (dp). |
enabled? | boolean | true | When disabled it takes no direction. |
PanGestureState
typeState of the drag (React Native PanResponderGestureState).
PanGestureOptions
interfaceOptions of usePanGesture.
| Name | Type | Default | Description |
|---|---|---|---|
claim? | GestureClaim | "all" | Directions the drag takes. A move in other directions stays with the scroll above (or the outer gesture): a horizontal slider takes "horizontal" and the page keeps scrolling vertically. Directions can change with state (e.g. a carousel on its first slide does not give "right"; then a pull to the right stays with the navigator's "back" gesture). |
claimOnStart? | boolean | false | Starts as soon as touched; the scroll above does not start at all for this touch (a signature pad, a slider thumb). |
claimPinch? | boolean | false | Starts when a second finger lands (pinch to zoom). |
enabled? | boolean | true | When disabled it takes no touches. |
slop? | number | 8 | Distance at which the direction is decided (dp). |
shouldBegin? | (state: PanGestureState, event: GestureResponderEvent) => boolean | Extra condition: return false to not start even when the direction matches (e.g. only pulls that start at the edge). Do not put the direction condition here but in claim: the native side decides based on claim. | |
onTap? | (event: GestureResponderEvent) => void | A tap and release without dragging (e.g. jumping to the tapped spot on a slider). When given, the touch is tracked from the start but a drag still starts only in the claim direction; if the finger goes another way the scroll takes over and it does not count as a tap. | |
onBegin? | (event: GestureResponderEvent, state: PanGestureState) => void | The drag started. | |
onUpdate? | (event: GestureResponderEvent, state: PanGestureState) => void | The finger moved. | |
onEnd? | (event: GestureResponderEvent, state: PanGestureState, info: { readonly cancelled: boolean; }) => void | The drag ended. cancelled: it moved to another handler before the finger lifted, or the system cancelled it (the value must not be applied; revert to the old state). |
PanGesture
interfaceThe usePanGesture result; passed to GestureView as gesture.
| Name | Type | Description |
|---|---|---|
region | GestureRegion | Its region in the arbiter. |
panHandlers | GestureResponderHandlers | React Native responder handlers (GestureView binds them itself). |
isActive | (): boolean | Whether a drag is in progress right now. |