Skip to content

Commit 3f91ea5

Browse files
m-bertCopilotj-piasecki
authored
[docs] GestureHandlerRootView (#3970)
## Description I've found it a bit frustrating that our docs do not have specific entry for `GestureHandlerRootView`, even though they reference it pretty often. Also because of that `installation` page served a purpose of component description, rather than showing quick setup. I've extracted root view information to specific page in **fundamentals** section ## Test plan Read docs 🤓 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jakub Piasecki <jakub.piasecki@swmansion.com>
1 parent 67006d6 commit 3f91ea5

File tree

12 files changed

+60
-26
lines changed

12 files changed

+60
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
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';

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/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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Setting up `react-native-gesture-handler` is pretty straightforward:
4747
</TabItem>
4848
</Tabs>
4949

50-
### 2. Wrap your app with `GestureHandlerRootView` component
50+
### 2. Wrap your app with GestureHandlerRootView component
5151

5252
```jsx
5353
import { GestureHandlerRootView } from 'react-native-gesture-handler';
@@ -62,21 +62,7 @@ export default function App() {
6262
```
6363
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.
6464

65-
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.
66-
67-
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.
68-
69-
:::note
70-
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.
71-
:::
72-
73-
#### Using `GestureHandlerRootView` with third party libraries
74-
75-
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.
76-
77-
:::tip
78-
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.
79-
:::
65+
Check out [`GestureHandlerRootView`](/docs/fundamentals/root-view) section for more details.
8066

8167
### 3. Platform specific setup
8268

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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
When integrating with navigation libraries, wrapping the navigator component with `GestureHandlerRootView` is generally sufficient. However, if you encounter issues with gestures not functioning properly, you might need to wrap each individual screen component with `GestureHandlerRootView` as well.
26+
:::
27+
28+
:::tip
29+
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.
30+
:::
31+
32+
## Styling
33+
34+
`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).
35+
36+
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.
37+
38+
## Nesting root views
39+
40+
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.
41+
42+
## unstable_forceActive
43+
44+
```ts
45+
unstable_forceActive?: boolean;
46+
```
47+
48+
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.

packages/docs-gesture-handler/docs/fundamentals/state-manager.mdx

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

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

0 commit comments

Comments
 (0)