-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[docs] Gesture detectors #3894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
[docs] Gesture detectors #3894
Conversation
| } | ||
| ``` | ||
|
|
||
| #### Usage with Animated API |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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({}); |
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
|
|
||
| `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. |
There was a problem hiding this comment.
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.
| const outerTap = useTapGesture({}); | ||
| const innerTap = useTapGesture({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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}> |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
Description
In this PR, page dedicated to gesture detectors is rewritten.
Test plan
Read docs 🤓