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
## Description
This PR:
- Removes **Introduction** and **Installation** pages
- Adds new "Getting started" page, which is a combination of the two
mentioned above
- Makes `npm` default tab in **Setup** section
- Adds "Your first gesture" section
- Fixes ordering of pages in side bar
## Test plan
Read docs 🤓
---------
Co-authored-by: Jakub Piasecki <jakub.piasecki@swmansion.com>
Copy file name to clipboardExpand all lines: packages/docs-gesture-handler/docs/fundamentals/animated-interactions.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
id: animated-interactions
3
3
title: Integration with Animated
4
4
sidebar_label: Integration with Animated
5
-
sidebar_position: 8
5
+
sidebar_position: 7
6
6
---
7
7
8
8
Using hook API allows for smooth integration with the [Animated API](https://reactnative.dev/docs/animated) by allowing for passing an `Animated.event` as the argument to the [`onUpdate`](/docs/fundamentals/callbacks-events#onupdate) callback. The event mapping of `Animated.event` depends on the [`useNativeDriver`](https://reactnative.dev/docs/animated#using-the-native-driver) property.
Gesture Handler provides a declarative API exposing the native platform's touch and gesture system to React Native. It's designed to be a replacement of React Native's built in touch system called [Gesture Responder System](http://reactnative.dev/docs/gesture-responder-system). Using native touch handling allows addressing the performance limitations of React Native's Gesture Responder System. It also provides more control over the platform's native components that can handle gestures on their own.
13
13
14
-
### Compatibility with React Native versions
14
+
## Installation
15
+
16
+
### Requirements
17
+
18
+
#### Compatibility with React Native versions
15
19
16
20
`react-native-gesture-handler` supports the three latest minor releases of `react-native`.
Using Reanimated is the recommended method of handling gesture-driven interactions on the UI thread. In order to use it, you need to install [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/) along with [`react-native-worklets`](https://docs.swmansion.com/react-native-worklets/). Another approach is to use React Native's [Animated API](https://reactnative.dev/docs/animated).
23
27
24
28
For more details on how to implement these, refer to the dedicated sections for [Reanimated](/docs/fundamentals/reanimated-interactions) and [Animated](/docs/fundamentals/animated-interactions).
25
29
26
-
## Setup
30
+
###Setup
27
31
28
32
Setting up `react-native-gesture-handler` is pretty straightforward:
29
33
30
-
### 1. Start with installing the package from npm:
34
+
####1. Start with installing the package from npm:
31
35
32
36
<TabsgroupId="package-managers">
33
-
<TabItemvalue="expo"label="EXPO"default>
34
-
```bash
35
-
npx expo install react-native-gesture-handler
36
-
```
37
-
</TabItem>
38
-
<TabItemvalue="npm"label="NPM">
37
+
<TabItemvalue="npm"label="NPM"default>
39
38
```bash
40
39
npm install react-native-gesture-handler
41
40
```
@@ -45,9 +44,14 @@ Setting up `react-native-gesture-handler` is pretty straightforward:
45
44
yarn add react-native-gesture-handler
46
45
```
47
46
</TabItem>
47
+
<TabItemvalue="expo"label="EXPO">
48
+
```bash
49
+
npx expo install react-native-gesture-handler
50
+
```
51
+
</TabItem>
48
52
</Tabs>
49
53
50
-
### 2. Wrap your app with GestureHandlerRootView component
54
+
####2. Wrap your app with GestureHandlerRootView component
@@ -64,7 +68,7 @@ Keep `GestureHandlerRootView` as close to the actual root of the app as possible
64
68
65
69
Check out [`GestureHandlerRootView`](/docs/fundamentals/root-view) section for more details.
66
70
67
-
### 3. Platform specific setup
71
+
####3. Platform specific setup
68
72
69
73
#### [Expo development build](https://docs.expo.dev/develop/development-builds/introduction/)
70
74
@@ -74,7 +78,7 @@ When using an Expo development build, run prebuild to update the native code in
74
78
npx expo prebuild
75
79
```
76
80
77
-
#### Android
81
+
#####Android
78
82
79
83
Setting up Gesture Handler on Android doesn't require any more steps. Keep in mind that if you want to use gestures in [Modals](https://reactnative.dev/docs/modal) you need to wrap Modal's content with `GestureHandlerRootView`:
If you are using a native navigation library like [wix/react-native-navigation](https://github.com/wix/react-native-navigation) you need to make sure that every screen is wrapped with `GestureHandlerRootView`. This can be done for example at the stage when you register your screens. Here's an example:
117
121
@@ -121,7 +125,7 @@ import FirstTabScreen from './FirstTabScreen';
121
125
importSecondTabScreenfrom'./SecondTabScreen';
122
126
importPushedScreenfrom'./PushedScreen';
123
127
124
-
//register all screens of the app (including internal ones)
128
+
//Register all screens of the app (including internal ones)
125
129
exportfunctionregisterScreens() {
126
130
Navigation.registerComponent(
127
131
'example.FirstTabScreen',
@@ -160,3 +164,52 @@ export function registerScreens() {
160
164
```
161
165
162
166
You can check out [this example project](https://github.com/henrikra/nativeNavigationGestureHandler) to see this kind of set up in action.
167
+
168
+
## Your first gesture
169
+
170
+
With the setup done, you're ready to add your first gesture. Create a tap gesture with the [`useTapGesture`](/docs/gestures/use-tap-gesture) hook, attach it to a component with [`GestureDetector`](/docs/fundamentals/gesture-detectors#gesture-detector). Don't forget to wrap your app with [`GestureHandlerRootView`](/docs/fundamentals/root-view), as described in [previous section](/docs/fundamentals/getting-started#2-wrap-your-app-with-gesturehandlerrootview-component).
171
+
172
+
<CollapsibleCode
173
+
label="Show full example"
174
+
expandedLabel="Hide full example"
175
+
lineBounds={[1, 21]}
176
+
src={`
177
+
import { StyleSheet, View } from 'react-native';
178
+
import {
179
+
GestureDetector,
180
+
GestureHandlerRootView,
181
+
useTapGesture,
182
+
} from 'react-native-gesture-handler';
183
+
184
+
export default function App() {
185
+
const tap = useTapGesture({
186
+
onActivate: () => {
187
+
console.log('Tapped!');
188
+
},
189
+
});
190
+
191
+
return (
192
+
<GestureHandlerRootView style={styles.container}>
193
+
<GestureDetector gesture={tap}>
194
+
<View style={styles.box} />
195
+
</GestureDetector>
196
+
</GestureHandlerRootView>
197
+
);
198
+
}
199
+
200
+
const styles = StyleSheet.create({
201
+
container: {
202
+
flex: 1,
203
+
alignItems: 'center',
204
+
justifyContent: 'center',
205
+
},
206
+
box: {
207
+
width: 80,
208
+
height: 80,
209
+
backgroundColor: '#b58df1',
210
+
borderRadius: 12,
211
+
},
212
+
});
213
+
`}/>
214
+
215
+
That's it! The gesture fires `onActivate` whenever a tap is recognized. Check out [Gesture callbacks & events](/docs/fundamentals/callbacks-events) for the full set of callbacks, or browse [all gestures](/docs/category/gestures) to keep exploring.
Copy file name to clipboardExpand all lines: packages/docs-gesture-handler/docs/fundamentals/reanimated-interactions.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
id: reanimated-interactions
3
3
title: Integration with Reanimated
4
4
sidebar_label: Integration with Reanimated
5
-
sidebar_position: 7
5
+
sidebar_position: 6
6
6
---
7
7
8
8
[`GestureDetector`](/docs/fundamentals/gesture-detectors) will decide whether to use [Reanimated](https://docs.swmansion.com/react-native-reanimated/) to process provided gestures based on their configuration. If any of the callbacks is a [worklet](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary/#worklet) and Reanimated is not explicitly [turned off](#disabling-reanimated), tools provided by the Reanimated will be utilized, bringing the ability to handle gestures synchronously on the main thread.
Copy file name to clipboardExpand all lines: packages/docs-gesture-handler/docs/fundamentals/root-view.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
id: root-view
3
3
title: GestureHandlerRootView
4
4
sidebar_label: GestureHandlerRootView
5
-
sidebar_position: 3
5
+
sidebar_position: 2
6
6
---
7
7
8
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).
Copy file name to clipboardExpand all lines: packages/docs-gesture-handler/docs/guides/troubleshooting.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ Thanks for giving this library a try! We are sorry that you might have encounter
15
15
2. When sure your problem hasn't been reported or was reported but the proposed solution doesn't work for you please follow [our issue reporting guidelines](#reporting-issues).
16
16
3. You can try seeking help on [Software Mansion Discord](https://discord.com/invite/VemJ4df8Yr).
17
17
4. If you feel like reading the source code we highly recommend it, as this is by far the best resource and gives you the most up to date insights into how the library works and what might be causing the bug.
18
-
5. If you managed to find the solution consider [contributing](/docs/fundamentals/introduction#contributing) a fix or update our documentation to make this information easier to find for others in the future.
18
+
5. If you managed to find the solution consider contributing a fix or update our documentation to make this information easier to find for others in the future.
0 commit comments