Skip to content

Commit 7f13def

Browse files
committed
Update instructions for importing gesture handler
1 parent de04713 commit 7f13def

File tree

6 files changed

+108
-30
lines changed

6 files changed

+108
-30
lines changed

versioned_docs/version-6.x/drawer-layout.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,25 @@ Then, you need to install and configure the libraries that are required by the d
3838

3939
The Drawer supports both Reanimated 1 and the latest version of Reanimated. If you want to use the latest version of Reanimated, make sure to configure it following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started).
4040

41-
2. To finalize installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
41+
2. To finalize the installation of `react-native-gesture-handler`, we need to conditionally import it. To do this, create 2 files:
4242

43-
```js
43+
```js title="gesture-handler.native.js"
44+
// Only import react-native-gesture-handler on native platforms
4445
import 'react-native-gesture-handler';
4546
```
4647

48+
```js title="gesture-handler.js"
49+
// Don't import react-native-gesture-handler on web
50+
```
51+
52+
Now, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
53+
54+
```js
55+
import './gesture-handler';
56+
```
57+
58+
Since the drawer layout doesn't use `react-native-gesture-handler` on the web, this avoids unnecessarily increasing the bundle size.
59+
4760
:::warning
4861

4962
If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.
@@ -52,9 +65,9 @@ Then, you need to install and configure the libraries that are required by the d
5265

5366
3. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
5467

55-
```bash
56-
npx pod-install ios
57-
```
68+
```bash
69+
npx pod-install ios
70+
```
5871

5972
We're done! Now you can build and run the app on your device/simulator.
6073

versioned_docs/version-6.x/drawer-navigator.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,25 @@ Then, you need to install and configure the libraries that are required by the d
3838

3939
The Drawer supports both Reanimated 1 and the latest version of Reanimated. If you want to use the latest version of Reanimated, make sure to configure it following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started).
4040

41-
2. To finalize installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
41+
2. To finalize the installation of `react-native-gesture-handler`, we need to conditionally import it. To do this, create 2 files:
4242

43-
```js
43+
```js title="gesture-handler.native.js"
44+
// Only import react-native-gesture-handler on native platforms
4445
import 'react-native-gesture-handler';
4546
```
4647

48+
```js title="gesture-handler.js"
49+
// Don't import react-native-gesture-handler on web
50+
```
51+
52+
Now, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
53+
54+
```js
55+
import './gesture-handler';
56+
```
57+
58+
Since the drawer navigator doesn't use `react-native-gesture-handler` on the web, this avoids unnecessarily increasing the bundle size.
59+
4760
:::warning
4861

4962
If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.
@@ -52,9 +65,9 @@ Then, you need to install and configure the libraries that are required by the d
5265

5366
3. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
5467

55-
```bash
56-
npx pod-install ios
57-
```
68+
```bash
69+
npx pod-install ios
70+
```
5871

5972
## API Definition
6073

versioned_docs/version-6.x/stack-navigator.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,25 @@ Then, you need to install and configure the libraries that are required by the s
3838
npm install react-native-gesture-handler
3939
```
4040

41-
2. To finalize installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
41+
2. To finalize the installation of `react-native-gesture-handler`, we need to conditionally import it. To do this, create 2 files:
4242

43-
```js
43+
```js title="gesture-handler.native.js"
44+
// Only import react-native-gesture-handler on native platforms
4445
import 'react-native-gesture-handler';
4546
```
4647

48+
```js title="gesture-handler.js"
49+
// Don't import react-native-gesture-handler on web
50+
```
51+
52+
Now, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
53+
54+
```js
55+
import './gesture-handler';
56+
```
57+
58+
Since the stack navigator doesn't use `react-native-gesture-handler` on the web, this avoids unnecessarily increasing the bundle size.
59+
4760
:::warning
4861

4962
If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.
@@ -66,9 +79,9 @@ Then, you need to install and configure the libraries that are required by the s
6679

6780
4. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
6881

69-
```bash
70-
npx pod-install ios
71-
```
82+
```bash
83+
npx pod-install ios
84+
```
7285

7386
## API Definition
7487

versioned_docs/version-7.x/drawer-layout.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,25 @@ Then, you need to install and configure the libraries that are required by the d
3838

3939
2. Configure the Reanimated Babel Plugin in your project following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started).
4040

41-
3. To finalize the installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
41+
3. To finalize the installation of `react-native-gesture-handler`, we need to conditionally import it. To do this, create 2 files:
4242

43-
```js
43+
```js title="gesture-handler.native.js"
44+
// Only import react-native-gesture-handler on native platforms
4445
import 'react-native-gesture-handler';
4546
```
4647

48+
```js title="gesture-handler.js"
49+
// Don't import react-native-gesture-handler on web
50+
```
51+
52+
Now, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
53+
54+
```js
55+
import './gesture-handler';
56+
```
57+
58+
Since the drawer layout doesn't use `react-native-gesture-handler` on the web, this avoids unnecessarily increasing the bundle size.
59+
4760
:::warning
4861

4962
If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.
@@ -52,9 +65,9 @@ Then, you need to install and configure the libraries that are required by the d
5265

5366
4. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
5467

55-
```bash
56-
npx pod-install ios
57-
```
68+
```bash
69+
npx pod-install ios
70+
```
5871

5972
We're done! Now you can build and run the app on your device/simulator.
6073

versioned_docs/version-7.x/drawer-navigator.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,25 @@ Then, you need to install and configure the libraries that are required by the d
3838

3939
2. Configure the Reanimated Babel Plugin in your project following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started).
4040

41-
3. To finalize the installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
41+
3. To finalize the installation of `react-native-gesture-handler`, we need to conditionally import it. To do this, create 2 files:
4242

43-
```js
43+
```js title="gesture-handler.native.js"
44+
// Only import react-native-gesture-handler on native platforms
4445
import 'react-native-gesture-handler';
4546
```
4647

48+
```js title="gesture-handler.js"
49+
// Don't import react-native-gesture-handler on web
50+
```
51+
52+
Now, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
53+
54+
```js
55+
import './gesture-handler';
56+
```
57+
58+
Since the drawer navigator doesn't use `react-native-gesture-handler` on the web, this avoids unnecessarily increasing the bundle size.
59+
4760
:::warning
4861

4962
If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.
@@ -52,9 +65,9 @@ Then, you need to install and configure the libraries that are required by the d
5265

5366
4. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
5467

55-
```bash
56-
npx pod-install ios
57-
```
68+
```bash
69+
npx pod-install ios
70+
```
5871

5972
## Usage
6073

versioned_docs/version-7.x/stack-navigator.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,25 @@ Then, you need to install and configure the libraries that are required by the s
4242
npm install react-native-gesture-handler
4343
```
4444

45-
2. To finalize installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
45+
2. To finalize the installation of `react-native-gesture-handler`, we need to conditionally import it. To do this, create 2 files:
4646

47-
```js
47+
```js title="gesture-handler.native.js"
48+
// Only import react-native-gesture-handler on native platforms
4849
import 'react-native-gesture-handler';
4950
```
5051

52+
```js title="gesture-handler.js"
53+
// Don't import react-native-gesture-handler on web
54+
```
55+
56+
Now, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`:
57+
58+
```js
59+
import './gesture-handler';
60+
```
61+
62+
Since the stack navigator doesn't use `react-native-gesture-handler` on the web, this avoids unnecessarily increasing the bundle size.
63+
5164
:::warning
5265

5366
If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.
@@ -70,9 +83,9 @@ Then, you need to install and configure the libraries that are required by the s
7083

7184
4. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.
7285

73-
```bash
74-
npx pod-install ios
75-
```
86+
```bash
87+
npx pod-install ios
88+
```
7689

7790
## Usage
7891

0 commit comments

Comments
 (0)