You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/getting-started.md
+70-69Lines changed: 70 additions & 69 deletions
Original file line number
Diff line number
Diff line change
@@ -19,17 +19,7 @@ In a nutshell, the library provides:
19
19
20
20
## Installation
21
21
22
-
### Managed [Expo](https://expo.io)
23
-
24
-
To use the version of react-native-gesture-handler that is compatible with your managed Expo project, run `expo install react-native-gesture-handler`.
25
-
26
-
The Expo SDK incorporates the latest version of react-native-gesture-handler available at the time of each SDK release, so managed Expo apps might not always support all our latest features as soon as they are available.
27
-
28
-
### Bare [React Native](http://facebook.github.io/react-native/)
29
-
30
-
Since the library uses native support for handling gestures, it requires an extended installation to the norm. If you are starting a new project, you may want to initialize it with [expo-cli](https://docs.expo.io/versions/latest/workflow/expo-cli/) and use a bare template, they come pre-installed with react-native-gesture-handler.
31
-
32
-
#### Requirements
22
+
### Requirements
33
23
34
24
| version |`react-native` version |
35
25
| --------- | ---------------------- |
@@ -42,7 +32,19 @@ Read more on that here https://github.com/mikehardy/jetifier#to-reverse-jetify--
42
32
43
33
Note that if you wish to use [`React.createRef()`](https://reactjs.org/docs/refs-and-the-dom.html) support for [interactions](interactions.md) you need to use v16.3 of [React](https://reactjs.org/)
44
34
45
-
#### JS
35
+
### Expo
36
+
37
+
#### Managed [Expo](https://expo.io)
38
+
39
+
To use the version of react-native-gesture-handler that is compatible with your managed Expo project, run `expo install react-native-gesture-handler`.
40
+
41
+
The Expo SDK incorporates the latest version of react-native-gesture-handler available at the time of each SDK release, so managed Expo apps might not always support all our latest features as soon as they are available.
42
+
43
+
#### Bare [React Native](http://facebook.github.io/react-native/)
44
+
45
+
Since the library uses native support for handling gestures, it requires an extended installation to the norm. If you are starting a new project, you may want to initialize it with [expo-cli](https://docs.expo.io/versions/latest/workflow/expo-cli/) and use a bare template, they come pre-installed with react-native-gesture-handler.
46
+
47
+
### JS
46
48
47
49
First, install the library using `yarn`:
48
50
@@ -56,6 +58,27 @@ or with `npm` if you prefer:
56
58
npm install --save react-native-gesture-handler
57
59
```
58
60
61
+
After installation, wrap your entry point with `<GestureHandlerRootView>` or
If you use props such as `shouldCancelWhenOutside`, `simultaneousHandlers`, `waitFor` etc. with gesture handlers, the handlers need to be mounted under a single `GestureHandlerRootView`. So it's important to keep the `GestureHandlerRootView` as close to the actual root view as possible.
74
+
75
+
Note that `GestureHandlerRootView` acts like a normal `View`. So if you want it to fill the screen, you will need to pass `{ flex: 1 }` like you'll need to do with a normal `View`. By default, it'll take the size of the content nested inside.
76
+
:::
77
+
78
+
:::tip
79
+
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.
80
+
:::
81
+
59
82
#### Linking
60
83
61
84
> **Important**: You only need to do this step if you're using React Native 0.59 or lower. Since v0.60, linking happens automatically.
If you use one of the _native navigation libraries_ (e.g. [wix/react-native-navigation](https://github.com/wix/react-native-navigation)), you should follow [this separate guide](#with-wixreact-native-navigation) to get gesture handler library set up on Android. Ignore the rest of this step – it only applies to RN apps that use a standard Android project layout.
94
+
If you use one of the _native navigation libraries_ (e.g.
you should follow [this separate guide](#with-wixreact-native-navigation) to get
97
+
gesture handler library set up on Android. Ignore the rest of this step – it
98
+
only applies to RN apps that use a standard Android project layout.
72
99
73
-
##### Updating `MainActivity.java`
100
+
#### Updating `MainActivity.java`
101
+
102
+
:::caution
103
+
From version 2.0.0 this step isn't needed. You should use
104
+
`<GestureHandlerRootView />` component instead.
105
+
:::
74
106
75
107
Update your `MainActivity.java` file (or wherever you create an instance of `ReactActivityDelegate`), so that it overrides the method responsible for creating `ReactRootView` instance and then use the root view wrapper provided by this library. Do not forget to import `ReactActivityDelegate`, `ReactRootView`, and `RNGestureHandlerEnabledRootView`:
76
108
@@ -101,33 +133,47 @@ public class MainActivity extends ReactActivity {
101
133
}
102
134
```
103
135
104
-
##### Running jetifier
136
+
####Usage with modals on Android
105
137
106
-
> **Important:** You only need to do this step if you're on React Native 0.60 or greater.
138
+
On Android RNGH does not work by default because modals are not located under React Native Root view in native hierarchy.
139
+
To fix that, components need to be wrapped with `gestureHandlerRootHOC` (it's no-op on iOS and web).
107
140
108
-
React Native 0.60 migrated from Support Library to AndroidX. React Native Gesture Handler is not yet compatible with AndroidX.
141
+
For example:
109
142
110
-
Make sure to [update the React Native CLI to the latest version](https://github.com/react-native-community/cli/tree/master#updating-the-cli) which runs [`jetifier`](https://www.npmjs.com/package/jetifier) – the AndroidX migration tool – during the `run-android` command.
143
+
```js
144
+
constExampleWithHoc=gestureHandlerRootHOC(() => (
145
+
<View>
146
+
<DraggableBox />
147
+
</View>
148
+
);
149
+
);
150
+
151
+
exportdefaultfunctionExample() {
152
+
return (
153
+
<Modal>
154
+
<ExampleWithHoc />
155
+
</Modal>
156
+
);
157
+
}
158
+
```
111
159
112
-
####iOS
160
+
### iOS
113
161
114
162
There is no additional configuration required on iOS except what follows in the next steps.
115
163
116
164
If you're in a CocoaPods project (the default setup since React Native 0.60),
117
165
make sure to install pods before you run your app:
118
166
119
-
```sh
167
+
```bash
120
168
cd ios && pod install
121
169
```
122
170
123
171
For React Native 0.61 or greater, add the library as the first import in your index.js file:
124
172
125
-
```
173
+
```js
126
174
import'react-native-gesture-handler';
127
175
```
128
176
129
-
Now you're all set. Run your app with `react-native run-android` or `react-native run-ios`.
130
-
131
177
### With [wix/react-native-navigation](https://github.com/wix/react-native-navigation)
132
178
133
179
If you are using a native navigation library like [wix/react-native-navigation](https://github.com/wix/react-native-navigation) you need to follow a different setup for your Android app to work properly. The reason is that both native navigation libraries and Gesture Handler library need to use their own special subclasses of `ReactRootView`.
@@ -166,51 +212,6 @@ You can check out [this example project](https://github.com/henrikra/nativeNavig
166
212
167
213
Remember that you need to wrap each screen that you use in your app with `gestureHandlerRootHOC` as with native navigation libraries each screen maps to a separate root view. It will not be enough to wrap the main screen only.
168
214
169
-
### Usage with modals on Android
170
-
171
-
On Android RNGH does not work by default because modals are not located under React Native Root view in native hierarchy.
172
-
In order to make it workable, components need to be wrapped with `gestureHandlerRootHOC` (it's no-op on iOS and web).
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 in `MainActivity.java` for the user.
If you use props such as `shouldCancelWhenOutside`, `simultaneousHandlers`, `waitFor` etc. with gesture handlers, the handlers need to be mounted under a single `GestureHandlerRootView`. So it's important to keep the `GestureHandlerRootView` as close to the actual root view as possible.
211
-
212
-
Note that `GestureHandlerRootView` acts like a normal `View`. So if you want it to fill the screen, you will need to pass `{ flex: 1 }` like you'll need to do with a normal `View`. By default, it'll take the size of the content nested inside.
213
-
214
215
### Testing
215
216
216
217
In order to load mocks provided by the library add following to your jest config in `package.json`:
0 commit comments