Skip to content

Commit 27e61dc

Browse files
authored
Deprecate RNGestureHandlerEnabledRootView (#1605)
1 parent db9954c commit 27e61dc

File tree

2 files changed

+71
-69
lines changed

2 files changed

+71
-69
lines changed

android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.view.MotionEvent
77
import com.facebook.react.ReactInstanceManager
88
import com.facebook.react.ReactRootView
99

10+
@Deprecated(message = "Use <GestureHandlerRootView /> component instead. Check gesture handler installation instructions in documentation for more information.")
1011
class RNGestureHandlerEnabledRootView : ReactRootView {
1112
private lateinit var _reactInstanceManager: ReactInstanceManager
1213
private var gestureRootHelper: RNGestureHandlerRootHelper? = null

docs/docs/getting-started.md

Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,7 @@ In a nutshell, the library provides:
1919

2020
## Installation
2121

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
3323

3424
| version | `react-native` version |
3525
| --------- | ---------------------- |
@@ -42,7 +32,19 @@ Read more on that here https://github.com/mikehardy/jetifier#to-reverse-jetify--
4232

4333
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/)
4434

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
4648

4749
First, install the library using `yarn`:
4850

@@ -56,6 +58,27 @@ or with `npm` if you prefer:
5658
npm install --save react-native-gesture-handler
5759
```
5860

61+
After installation, wrap your entry point with `<GestureHandlerRootView>` or
62+
`gestureHandlerRootHOC`.
63+
64+
For example:
65+
66+
```js
67+
export default function App() {
68+
return <GestureHandlerRootView>{/* content */}</GestureHandlerRootView>;
69+
}
70+
```
71+
72+
:::info
73+
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+
5982
#### Linking
6083

6184
> **Important**: You only need to do this step if you're using React Native 0.59 or lower. Since v0.60, linking happens automatically.
@@ -64,13 +87,22 @@ npm install --save react-native-gesture-handler
6487
react-native link react-native-gesture-handler
6588
```
6689

67-
#### Android
90+
### Android
6891

6992
Follow the steps below:
7093

71-
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.
95+
[wix/react-native-navigation](https://github.com/wix/react-native-navigation)),
96+
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.
7299

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+
:::
74106

75107
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`:
76108

@@ -101,33 +133,47 @@ public class MainActivity extends ReactActivity {
101133
}
102134
```
103135

104-
##### Running jetifier
136+
#### Usage with modals on Android
105137

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).
107140

108-
React Native 0.60 migrated from Support Library to AndroidX. React Native Gesture Handler is not yet compatible with AndroidX.
141+
For example:
109142

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+
const ExampleWithHoc = gestureHandlerRootHOC(() => (
145+
<View>
146+
<DraggableBox />
147+
</View>
148+
);
149+
);
150+
151+
export default function Example() {
152+
return (
153+
<Modal>
154+
<ExampleWithHoc />
155+
</Modal>
156+
);
157+
}
158+
```
111159

112-
#### iOS
160+
### iOS
113161

114162
There is no additional configuration required on iOS except what follows in the next steps.
115163

116164
If you're in a CocoaPods project (the default setup since React Native 0.60),
117165
make sure to install pods before you run your app:
118166

119-
```sh
167+
```bash
120168
cd ios && pod install
121169
```
122170

123171
For React Native 0.61 or greater, add the library as the first import in your index.js file:
124172

125-
```
173+
```js
126174
import 'react-native-gesture-handler';
127175
```
128176

129-
Now you're all set. Run your app with `react-native run-android` or `react-native run-ios`.
130-
131177
### With [wix/react-native-navigation](https://github.com/wix/react-native-navigation)
132178

133179
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
166212

167213
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.
168214

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).
173-
174-
E.g.
175-
176-
```js
177-
const ExampleWithHoc = gestureHandlerRootHOC(function GestureExample() {
178-
return (
179-
<View>
180-
<DraggableBox />
181-
</View>
182-
);
183-
});
184-
185-
export default function Example() {
186-
return (
187-
<Modal animationType="slide" transparent={false}>
188-
<ExampleWithHoc />
189-
</Modal>
190-
);
191-
}
192-
```
193-
194-
### For library authors
195-
196-
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.
197-
198-
```js
199-
import { GestureHandlerRootView } from 'react-native-gesture-handler';
200-
201-
export default MyComponent() {
202-
return (
203-
<GestureHandlerRootView>
204-
{/* content */}
205-
</GestureHandlerRootView>
206-
)
207-
}
208-
```
209-
210-
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-
214215
### Testing
215216

216217
In order to load mocks provided by the library add following to your jest config in `package.json`:

0 commit comments

Comments
 (0)