Skip to content

Commit 5b5db8a

Browse files
authored
Update documentation page about the Native gesture (#3272)
## Description Updates the documentation for the `Native` gesture with a warning about components from RNGH and an example.
1 parent d93bfe3 commit 5b5db8a

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

docs/docs/gestures/native-gesture.md

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,77 @@ import BaseEventConfig from './\_shared/base-gesture-config.md';
1010
import BaseEventCallbacks from './\_shared/base-gesture-callbacks.md';
1111
import BaseContinuousEventCallbacks from './\_shared/base-continuous-gesture-callbacks.md';
1212

13-
A gesture that allows other touch handling components to participate in RNGH's gesture system. When used, the other component should be the direct child of a `GestureDetector`.
13+
A gesture that allows other touch handling components to work within RNGH's gesture system. This streamlines interactions between gestures and the native component, allowing it to form [relations](/docs/fundamentals/gesture-composition) with other gestures.
1414

15-
## Reference
15+
When used, the native component should be the direct child of a `GestureDetector`.
16+
17+
## Example
18+
19+
This example renders a `ScrollView` with multiple colored rectangles, where each rectangle has a black section. Starting a touch on a black section will disable the `ScrollView` for the duration of the `Pan` gesture.
1620

1721
```jsx
18-
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
22+
import { View, ScrollView } from 'react-native';
23+
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
1924

20-
function App() {
25+
const COLORS = ['red', 'green', 'blue', 'purple', 'orange', 'cyan'];
26+
27+
export default function App() {
2128
// highlight-next-line
2229
const native = Gesture.Native();
2330

2431
return (
2532
<GestureDetector gesture={native}>
26-
<View />
33+
<ScrollView style={{ flex: 1 }}>
34+
<ScrollableContent scrollGesture={native} />
35+
</ScrollView>
2736
</GestureDetector>
2837
);
2938
}
39+
40+
function ScrollableContent({ scrollGesture }) {
41+
return (
42+
<View>
43+
{COLORS.map((color) => (
44+
<Rectangle key={color} color={color} scrollGesture={scrollGesture} />
45+
))}
46+
</View>
47+
);
48+
}
49+
50+
function Rectangle({ color, scrollGesture }) {
51+
const pan = Gesture.Pan().blocksExternalGesture(scrollGesture);
52+
53+
return (
54+
<View
55+
key={color}
56+
style={{ width: '100%', height: 250, backgroundColor: color }}>
57+
<GestureDetector gesture={pan}>
58+
<View style={{ width: '100%', height: 50, backgroundColor: 'black' }} />
59+
</GestureDetector>
60+
</View>
61+
);
62+
}
3063
```
3164

65+
## Remarks
66+
67+
- `Native` gesture can be used as part of [gesture composition and cross-component interactions](/docs/fundamentals/gesture-composition) just like any other gesture. You can use this to block a native component for the duration of the gesture or to make it work alongside a gesture.
68+
69+
:::danger
70+
Do not use `Native` gesture with components exported by React Native Gesture Handler. Those come with a native gesture handler preapplied. Attaching a native gesture twice will likely result in the components not working as intended.
71+
:::
72+
3273
## Config
3374

3475
### Properties specific to `NativeGesture`:
3576

3677
### `shouldActivateOnStart(value: boolean)` (**Android only**)
3778

38-
When `true`, underlying handler will activate unconditionally when in `BEGAN` or `UNDETERMINED` state.
79+
When `true`, underlying handler will activate unconditionally when it receives any touches in [`BEGAN`](/docs/fundamentals/states-events#began) or [`UNDETERMINED`](/docs/fundamentals/states-events#undetermined) state.
3980

4081
### `disallowInterruption(value: boolean)`
4182

42-
When `true`, cancels all other gesture handlers when this `NativeViewGestureHandler` receives an `ACTIVE` state event.
83+
When `true`, cancels all other gesture handlers when this `NativeViewGestureHandler` changes its state to [`ACTIVE`](/docs/fundamentals/states-events#active).
4384

4485
<BaseEventConfig />
4586

0 commit comments

Comments
 (0)