Skip to content

Commit 4a901f8

Browse files
committed
Add root view page
1 parent 6d909f3 commit 4a901f8

13 files changed

Lines changed: 58 additions & 29 deletions

packages/docs-gesture-handler/docs/components/pressable.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This component is a drop-in replacement for the `Pressable` component.
1717

1818
`Pressable` is a component that can detect various stages of tap, press, and hover interactions on any of its children.
1919

20-
To use `Pressable`, ensure that your app is wrapped in `GestureHandlerRootView` and import it as follows:
20+
To use `Pressable`, ensure that your app is wrapped in [`GestureHandlerRootView`](/docs/fundamentals/root-view) and import it as follows:
2121

2222
```ts
2323
import { Pressable } from 'react-native-gesture-handler';
@@ -222,7 +222,7 @@ lineBounds={[5, 20]}
222222
src={`
223223
import { View, Text, StyleSheet } from 'react-native';
224224
import {
225-
GestureHandlerRootView,
225+
,
226226
Pressable,
227227
} from 'react-native-gesture-handler';
228228

packages/docs-gesture-handler/docs/components/reanimated-drawer-layout.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
1010
This component acts as a cross-platform replacement for React Native's [`DrawerLayoutAndroid`](http://reactnative.dev/docs/drawerlayoutandroid.html) component, written using [Reanimated](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started). For detailed information on standard parameters, please refer to the [React Native documentation](http://reactnative.dev/docs/drawerlayoutandroid.html).
1111
:::
1212

13-
To use `ReanimatedDrawerLayout`, first ensure that Reanimated is installed and that your app is wrapped in `GestureHandlerRootView`. You can then import it as follows:
13+
To use `ReanimatedDrawerLayout`, first ensure that Reanimated is installed and that your app is wrapped in [`GestureHandlerRootView`](/docs/fundamentals/root-view). You can then import it as follows:
1414

1515
```ts
1616
import ReanimatedDrawerLayout from 'react-native-gesture-handler/ReanimatedDrawerLayout';

packages/docs-gesture-handler/docs/components/reanimated_swipeable.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This component is a drop-in replacement for the `Swipeable` component, rewritten
1818

1919
Reanimated `Swipeable` is designed for implementing swipeable rows or similar interactions. It places its children inside a pannable container that enables horizontal swiping to the left and right. Depending on the direction of the swipe, one of two "action" containers will be displayed, which can be configured using the [`renderLeftActions`](#renderleftactions) or [`renderRightActions`](#renderrightactions) props.
2020

21-
To use Reanimated `Swipeable`, first ensure that Reanimated is installed and that your app is wrapped in `GestureHandlerRootView`. You can then import it as follows:
21+
To use Reanimated `Swipeable`, first ensure that Reanimated is installed and that your app is wrapped in [`GestureHandlerRootView`](/docs/fundamentals/root-view). You can then import it as follows:
2222

2323
```ts
2424
import Swipeable from 'react-native-gesture-handler/ReanimatedSwipeable';

packages/docs-gesture-handler/docs/fundamentals/animated-interactions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: animated-interactions
33
title: Integration with Animated
44
sidebar_label: Integration with Animated
5-
sidebar_position: 5
5+
sidebar_position: 9
66
---
77

88
import CollapsibleCode from '@site/src/components/CollapsibleCode';

packages/docs-gesture-handler/docs/fundamentals/callbacks-events.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: callbacks-events
33
title: Gesture callbacks & events
44
sidebar_label: Gesture callbacks & events
5-
sidebar_position: 7
5+
sidebar_position: 6
66
---
77

88
import { GestureEventFlowChart, TouchEventFlowChart } from '@site/src/examples/CallbacksFlowCharts'

packages/docs-gesture-handler/docs/fundamentals/gesture-composition.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: gesture-composition
33
title: Gesture composition & interactions
44
sidebar_label: Gesture composition & interactions
5-
sidebar_position: 6
5+
sidebar_position: 5
66
---
77

88
import CollapsibleCode from '@site/src/components/CollapsibleCode';

packages/docs-gesture-handler/docs/fundamentals/gesture-detector.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: gesture-detectors
33
title: Gesture Detectors
44
sidebar_label: Gesture detectors
5-
sidebar_position: 3
5+
sidebar_position: 4
66
---
77

88
import CollapsibleCode from '@site/src/components/CollapsibleCode';

packages/docs-gesture-handler/docs/fundamentals/installation.mdx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Setting up `react-native-gesture-handler` is pretty straightforward:
4545
</TabItem>
4646
</Tabs>
4747

48-
### 2. Wrap your app with `GestureHandlerRootView` component
48+
### 2. Wrap your app with GestureHandlerRootViewcomponent
4949

5050
```jsx
5151
import { GestureHandlerRootView } from 'react-native-gesture-handler';
@@ -58,23 +58,8 @@ export default function App() {
5858
);
5959
}
6060
```
61-
Keep `GestureHandlerRootView` as close to the actual root of the app as possible. It's the entry point for all gestures and all [gesture relations](/docs/fundamentals/gesture-composition). The gestures won't be recognized outside of the root view, and relations only work between gestures mounted under the same root view.
6261

63-
If you don't provide anything to the `styles` prop, it will default to `flex: 1`. If you want to customize the styling of the root view, don't forget to also include `flex: 1` in the custom style, otherwise your app won't render anything.
64-
65-
If you're unsure if one of your dependencies already renders `GestureHandlerRootView` on its own, don't worry and add one at the root anyway. In case of nested root views, Gesture Handler will only use the top-most one and ignore the nested ones.
66-
67-
:::note
68-
Remember that you need to wrap each screen that you use in your app with `GestureHandlerRootView` as with native navigation libraries each screen maps to a separate root view. It will not be enough to wrap the main screen only.
69-
:::
70-
71-
#### Using `GestureHandlerRootView` with third party libraries
72-
73-
If you're having trouble with gestures not working when inside a component provided by a third-party library, even though you've wrapped the entry point with `<GestureHandlerRootView>`, you can try adding another `<GestureHandlerRootView unstable_forceActive>` closer to the place the gestures are defined. This way, you can prevent Android from canceling relevant gestures when one of the native views tries to grab lock for delivering touch events.
74-
75-
:::tip
76-
If you're using Gesture Handler in your component library, you may want to wrap your library's code in the `GestureHandlerRootView` component. This will avoid extra configuration for the user.
77-
:::
62+
Check out [`GestureHandlerRootView`](/docs/fundamentals/root-view) section for more details.
7863

7964
### 3. Platform specific setup
8065

packages/docs-gesture-handler/docs/fundamentals/reanimated-interactions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: reanimated-interactions
33
title: Integration with Reanimated
44
sidebar_label: Integration with Reanimated
5-
sidebar_position: 4
5+
sidebar_position: 8
66
---
77

88
import CollapsibleCode from '@site/src/components/CollapsibleCode';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
id: root-view
3+
title: GestureHandlerRootView
4+
sidebar_label: GestureHandlerRootView
5+
sidebar_position: 3
6+
---
7+
8+
`GestureHandlerRootView` is a key component that enables Gesture Handler to intercept touch events, allowing for the implementation of gestures in your app. It should wrap your app's main component, and any component that relies on Gesture Handler's gestures has to be a descendant of this view. For more detailed information, you can check out the [under-the-hood section](/docs/under-the-hood/how-does-it-work#android).
9+
10+
```tsx
11+
import { GestureHandlerRootView } from 'react-native-gesture-handler';
12+
13+
export default function App() {
14+
return (
15+
<GestureHandlerRootView>
16+
<ActualApp />
17+
</GestureHandlerRootView>
18+
);
19+
}
20+
```
21+
22+
Keep `GestureHandlerRootView` as close to the actual root of the app as possible. It's the entry point for all gestures and all [gesture relations](/docs/fundamentals/gesture-composition). The gestures won't be recognized outside of the root view, and relations only work between gestures mounted under the same root view.
23+
24+
:::note
25+
Remember that you need to wrap each screen that you use in your app with `GestureHandlerRootView` as with native navigation libraries each screen maps to a separate root view. It will not be enough to wrap the main screen only.
26+
:::
27+
28+
## Styling
29+
30+
`GestureHandlerRootView` can be thought of as a regular `View` component, therefore it accepts all the same props, including [`style`](https://reactnative.dev/docs/0.81/view-style-props).
31+
32+
If you don't provide anything to the `style` prop, it will default to `{ flex: 1 }`. If you want to customize the styling of the root view, don't forget to also include `flex: 1` in the custom style, otherwise your app won't render anything.
33+
34+
## Nesting root views
35+
36+
In case of nested root views, Gesture Handler will only use the top-most one and ignore the nested ones. If you're unsure if one of your dependencies already renders `GestureHandlerRootView` on its own, don't worry and add one at the root anyway.
37+
38+
## Using GestureHandlerRootView with third party libraries
39+
40+
If you're having trouble with gestures not working when inside a component provided by a third-party library, even though you've wrapped the entry point with `<GestureHandlerRootView>`, you can try adding another `<GestureHandlerRootView unstable_forceActive>` closer to the place the gestures are defined. This way, you can prevent Android from canceling relevant gestures when one of the native views tries to grab lock for delivering touch events.
41+
42+
:::tip
43+
If you're using Gesture Handler in your component library, you may want to wrap your library's code in the `GestureHandlerRootView` component. This will avoid extra configuration for the user.
44+
:::

0 commit comments

Comments
 (0)