Skip to content

Commit bc735eb

Browse files
committed
Add use cases
1 parent 79a2ff3 commit bc735eb

1 file changed

Lines changed: 76 additions & 2 deletions

File tree

packages/docs-gesture-handler/docs/fundamentals/gesture-detector.md renamed to packages/docs-gesture-handler/docs/fundamentals/gesture-detector.mdx

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ sidebar_label: Gesture detectors
55
sidebar_position: 3
66
---
77

8+
import CollapsibleCode from '@site/src/components/CollapsibleCode';
9+
10+
811
## Gesture Detector
912

1013
The `GestureDetector` is a key component of RNGH3. It supports gestures created either using the hooks API or the builder pattern. Additionally, it allows for the recognition of multiple gestures through [gesture composition](/docs/fundamentals/gesture-composition). `GestureDetector` interacts closely with [`Reanimated`](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/). For more details, refer to the [Integration with Reanimated](/docs/fundamentals/reanimated-interactions) section.
@@ -49,7 +52,19 @@ In RNGH3, `GestureDetector` is a standalone host component. Depending on your vi
4952

5053
`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.
5154

52-
```js
55+
### Known use cases
56+
57+
Here are some of the most common use cases for virtual gesture detectors.
58+
59+
#### SVG
60+
61+
You can combine `VirtualGestureDetector` with `react-native-svg` to add gesture handling to individual SVG elements.
62+
63+
<CollapsibleCode
64+
label="Show full example"
65+
expandedLabel="Hide full example"
66+
lineBounds={[10, 45]}
67+
src={`
5368
import React from 'react';
5469
import { View, StyleSheet } from 'react-native';
5570
import {
@@ -107,7 +122,66 @@ const styles = StyleSheet.create({
107122
backgroundColor: '#b58df1',
108123
},
109124
});
110-
```
125+
`}/>
126+
127+
128+
#### Text
129+
130+
You can use `VirtualGestureDetector` to add gesture handling to specific parts of a `Text` component.
131+
132+
<CollapsibleCode
133+
label="Show full example"
134+
expandedLabel="Hide full example"
135+
lineBounds={[8, 37]}
136+
src={`
137+
import * as React from 'react';
138+
import { StyleSheet, Text } from 'react-native';
139+
import {
140+
GestureHandlerRootView,
141+
InterceptingGestureDetector,
142+
VirtualGestureDetector,
143+
useTapGesture,
144+
} from 'react-native-gesture-handler';
145+
146+
export default function App() {
147+
const outerTap = useTapGesture({
148+
onDeactivate: () => {
149+
console.log('Tapped on text!');
150+
},
151+
});
152+
153+
const nestedTap = useTapGesture({
154+
onDeactivate: () => {
155+
console.log('Tapped on nested part!');
156+
},
157+
});
158+
159+
return (
160+
<GestureHandlerRootView style={styles.container}>
161+
<InterceptingGestureDetector gesture={outerTap}>
162+
<Text style={{ fontSize: 18, textAlign: 'center' }}>
163+
Nested text
164+
<VirtualGestureDetector gesture={nestedTap}>
165+
<Text style={{ fontSize: 24, color: '#001A72' }}>
166+
try tapping on this part.
167+
</Text>
168+
</VirtualGestureDetector>
169+
This part is not special :c
170+
</Text>
171+
</InterceptingGestureDetector>
172+
</GestureHandlerRootView>
173+
);
174+
}
175+
176+
const styles = StyleSheet.create({
177+
container: {
178+
flex: 1,
179+
alignItems: 'center',
180+
justifyContent: 'space-around',
181+
},
182+
});
183+
`}/>
184+
111185

112186
## Properties
113187

0 commit comments

Comments
 (0)