Skip to content

Conversation

@m-bert
Copy link
Contributor

@m-bert m-bert commented Dec 23, 2025

Description

In this PR, page dedicated to gesture detectors is rewritten.

Test plan

Read docs 🤓

@m-bert m-bert added the Documentation Documentation change/enhancement label Jan 9, 2026
@m-bert m-bert requested a review from akwasniewski January 9, 2026 15:14
}
```

#### Usage with Animated API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be worth its own page.


`GestureDetector` is the core component of RNGH3. Unlike in previous version, it no longer manages the lifecycle of gestures directly. It supports recognizing multiple gestures through [gesture composition](/docs/fundamentals/gesture-composition).

To facilitate a smooth migration, the gesture property accepts both RNGH3 and RNGH2 gestures.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To facilitate a smooth migration, the gesture property accepts both RNGH3 and RNGH2 gestures.
To facilitate a smooth migration, the gesture property accepts both gestures created using the hooks API and gestures created using the builder pattern.

I'm not sold on using RNGH2 and RNGH3 as a way to differentiate between the two APIs, especially given that some parts stayed the same (i.e. GestureDetector).

import { GestureDetector, useTapGesture } from 'react-native-gesture-handler';

export default function App() {
const tap = useTapGesture({});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this have a console.log at least?


## Gesture Detector

`GestureDetector` is the core component of RNGH3. Unlike in previous version, it no longer manages the lifecycle of gestures directly. It supports recognizing multiple gestures through [gesture composition](/docs/fundamentals/gesture-composition).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike in previous version, it no longer manages the lifecycle of gestures directly.

So what's the difference between the two versions?

I feel like this page should focus on what it does instead of on what it doesn't. We're going to have an entire migration guide about the differences.


## Virtual Detectors

In RNGH3, `GestureDetector` is a standalone native component. Depending on your view hierarchy, this can occasionally disrupt interactions between specific components. To resolve this, use `InterceptingGestureDetector` in combination with `VirtualNativeDetector`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, the established name is host component.


### InterceptingGestureDetector

`InterceptingGestureDetector` functions like a standard `GestureDetector`, but adds support for `VirtualGestureDetector` within its component subtree. Because it can be used solely to establish the context for virtual detectors, the [`gesture`](#gesture) property is optional.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`InterceptingGestureDetector` functions like a standard `GestureDetector`, but adds support for `VirtualGestureDetector` within its component subtree. Because it can be used solely to establish the context for virtual detectors, the [`gesture`](#gesture) property is optional.
`InterceptingGestureDetector` functions similarly to a standard `GestureDetector`, but it can also act as a proxy for `VirtualGestureDetector` within its component subtree. Because it can be used solely to establish the context for virtual detectors, the [`gesture`](#gesture) property is optional.

Idk, what do you think?


### VirtualGestureDetector

`VirtualGestureDetector` is similar to the `GestureDetector` from RNGH2. Because it is not a native component, it does not interfere with the native view hierarchy. This allows you to attach gestures without disrupting functionality that depends on that hierarchy.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`VirtualGestureDetector` is similar to the `GestureDetector` from RNGH2. Because it is not a native component, it does not interfere with the native view hierarchy. This allows you to attach gestures without disrupting functionality that depends on that hierarchy.
`VirtualGestureDetector` is similar to the `GestureDetector` from RNGH2. Because it is not a host component, it does not interfere with the host view hierarchy. This allows you to attach gestures without disrupting functionality that depends on it, like `react-native-svg` components.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think virtual detector deserves a known use case subsection: svg, nested text. People will search for it, and it will be easier for llm's to figure out if it is explicit.


## Interaction with Reanimated

`GestureDetector` will decide whether to use [Reanimated](https://docs.swmansion.com/react-native-reanimated/) to process provided gestures based on their configuration. If any of the callbacks is a worklet and Reanimated is not explicitly turned off, tools provided by the Reanimated will be utilized bringing ability to handle gestures synchronously.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`GestureDetector` will decide whether to use [Reanimated](https://docs.swmansion.com/react-native-reanimated/) to process provided gestures based on their configuration. If any of the callbacks is a worklet and Reanimated is not explicitly turned off, tools provided by the Reanimated will be utilized bringing ability to handle gestures synchronously.
`GestureDetector` will decide whether to use [Reanimated](https://docs.swmansion.com/react-native-reanimated/) to process provided gestures based on their configuration. If any of the callbacks is a worklet and Reanimated is not explicitly turned off, tools provided by Reanimated will be utilized, bringing the ability to handle gestures synchronously on the main thread.

}
```

This example will throw an error, becuse we try to use the same instance of `Pan` in two different Gesture Detectors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This example will throw an error, becuse we try to use the same instance of `Pan` in two different Gesture Detectors.
This example will throw an error, because the same instance of `Pan` is being used in two different Gesture Detectors.

akwasniewski
akwasniewski previously approved these changes Jan 14, 2026

`GestureDetector` is the core component of RNGH3. Unlike in previous version, it no longer manages the lifecycle of gestures directly. It supports recognizing multiple gestures through [gesture composition](/docs/fundamentals/gesture-composition).

To facilitate a smooth migration, the gesture property accepts both RNGH3 and RNGH2 gestures.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How nested GestureDetectors from different GH versions interact? I'm not sure we should indicate the user can use both in one component. Especially as relations definetly don't work.

Comment on lines +109 to +110
const outerTap = useTapGesture({});
const innerTap = useTapGesture({});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const outerTap = useTapGesture({});
const innerTap = useTapGesture({});
const outerTap = useTapGesture({onActivate: ()=> console.log("box tapped")});
const innerTap = useTapGesture({onActivate: ()=> console.log("circle tapped")});

<View style={styles.box}>
<Svg height="250" width="250">
// highlight-next-line
<VirtualGestureDetector gesture={outerTap}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner component's gesture should probably be innerTap and outer's outerTap


### VirtualGestureDetector

`VirtualGestureDetector` is similar to the `GestureDetector` from RNGH2. Because it is not a native component, it does not interfere with the native view hierarchy. This allows you to attach gestures without disrupting functionality that depends on that hierarchy.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think virtual detector deserves a known use case subsection: svg, nested text. People will search for it, and it will be easier for llm's to figure out if it is explicit.

}
```

This example will throw an error, becuse we try to use the same instance of `Pan` in two different Gesture Detectors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it throw an error though? I haven't checked on ios or android but web does not throw. It attaches to only one detector, but it is undefined behaviour which one. I think at some point we discussed where to put the error check in the office, but we figured it is not trivial, as we might break reattaching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Documentation change/enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants