Skip to content

Commit 8896a63

Browse files
m-bertj-piasecki
andauthored
[Docs] Add "Getting Started" page (#4362)
## 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>
1 parent bd8e57a commit 8896a63

13 files changed

Lines changed: 95 additions & 155 deletions

File tree

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: 8
5+
sidebar_position: 7
66
---
77

88
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.

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: 5
5+
sidebar_position: 4
66
---
77

88
import {

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: 4
5+
sidebar_position: 3
66
---
77

88
## Gesture Detector

packages/docs-gesture-handler/docs/fundamentals/installation.mdx renamed to packages/docs-gesture-handler/docs/fundamentals/getting-started.mdx

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
---
2-
id: installation
3-
title: Installation
4-
sidebar_position: 2
2+
id: getting-started
3+
title: Getting started
4+
sidebar_position: 1
55
---
66

77
import Tabs from '@theme/Tabs';
88
import TabItem from '@theme/TabItem';
99

1010
import { GestureHandlerCompatibility } from '../../components/Compatibility';
1111

12-
## Requirements
12+
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.
1313

14-
### Compatibility with React Native versions
14+
## Installation
15+
16+
### Requirements
17+
18+
#### Compatibility with React Native versions
1519

1620
`react-native-gesture-handler` supports the three latest minor releases of `react-native`.
1721

1822
<GestureHandlerCompatibility spacerAfterIndex={1} />
1923

20-
### Running gestures on the UI thread
24+
#### Running gestures on the UI thread
2125

2226
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).
2327

2428
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).
2529

26-
## Setup
30+
### Setup
2731

2832
Setting up `react-native-gesture-handler` is pretty straightforward:
2933

30-
### 1. Start with installing the package from npm:
34+
#### 1. Start with installing the package from npm:
3135

3236
<Tabs groupId="package-managers">
33-
<TabItem value="expo" label="EXPO" default>
34-
```bash
35-
npx expo install react-native-gesture-handler
36-
```
37-
</TabItem>
38-
<TabItem value="npm" label="NPM">
37+
<TabItem value="npm" label="NPM" default>
3938
```bash
4039
npm install react-native-gesture-handler
4140
```
@@ -45,9 +44,14 @@ Setting up `react-native-gesture-handler` is pretty straightforward:
4544
yarn add react-native-gesture-handler
4645
```
4746
</TabItem>
47+
<TabItem value="expo" label="EXPO">
48+
```bash
49+
npx expo install react-native-gesture-handler
50+
```
51+
</TabItem>
4852
</Tabs>
4953

50-
### 2. Wrap your app with GestureHandlerRootView component
54+
#### 2. Wrap your app with GestureHandlerRootView component
5155

5256
```jsx
5357
import { GestureHandlerRootView } from 'react-native-gesture-handler';
@@ -64,7 +68,7 @@ Keep `GestureHandlerRootView` as close to the actual root of the app as possible
6468

6569
Check out [`GestureHandlerRootView`](/docs/fundamentals/root-view) section for more details.
6670

67-
### 3. Platform specific setup
71+
#### 3. Platform specific setup
6872

6973
#### [Expo development build](https://docs.expo.dev/develop/development-builds/introduction/)
7074

@@ -74,7 +78,7 @@ When using an Expo development build, run prebuild to update the native code in
7478
npx expo prebuild
7579
```
7680

77-
#### Android
81+
##### Android
7882

7983
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`:
8084

@@ -91,27 +95,27 @@ export function CustomModal({ children, ...rest }) {
9195
}
9296
```
9397

94-
#### iOS
98+
##### iOS
9599

96100
While developing for iOS, make sure to install [pods](https://cocoapods.org/) first before running the app:
97101

98102
```bash
99103
cd ios && bundle install && bundle exec pod install && cd ..
100104
```
101105

102-
#### macOS
106+
##### macOS
103107

104108
While developing for macOS, make sure to install [pods](https://cocoapods.org/) first before running the app:
105109

106110
```bash
107111
cd macos && bundle install && bundle exec pod install && cd ..
108112
```
109113

110-
#### Web
114+
##### Web
111115

112116
There is no additional configuration required for the web.
113117

114-
#### With [wix/react-native-navigation](https://github.com/wix/react-native-navigation)
118+
##### With [wix/react-native-navigation](https://github.com/wix/react-native-navigation)
115119

116120
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:
117121

@@ -121,7 +125,7 @@ import FirstTabScreen from './FirstTabScreen';
121125
import SecondTabScreen from './SecondTabScreen';
122126
import PushedScreen from './PushedScreen';
123127

124-
// register all screens of the app (including internal ones)
128+
// Register all screens of the app (including internal ones)
125129
export function registerScreens() {
126130
Navigation.registerComponent(
127131
'example.FirstTabScreen',
@@ -160,3 +164,52 @@ export function registerScreens() {
160164
```
161165

162166
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.

packages/docs-gesture-handler/docs/fundamentals/introduction.md

Lines changed: 0 additions & 121 deletions
This file was deleted.

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: 7
5+
sidebar_position: 6
66
---
77

88
[`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.

packages/docs-gesture-handler/docs/fundamentals/root-view.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: root-view
33
title: GestureHandlerRootView
44
sidebar_label: GestureHandlerRootView
5-
sidebar_position: 3
5+
sidebar_position: 2
66
---
77

88
`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).

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: 5
66
---
77

88
RNGH3 allows manually controlling the [gestures' lifecycle](/docs/under-the-hood/state) by using [`GestureStateManager`](#gesturestatemanager).

packages/docs-gesture-handler/docs/guides/troubleshooting.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Thanks for giving this library a try! We are sorry that you might have encounter
1515
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).
1616
3. You can try seeking help on [Software Mansion Discord](https://discord.com/invite/VemJ4df8Yr).
1717
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.
1919

2020
## Reporting issues
2121

packages/docs-gesture-handler/docusaurus.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const config = {
8181
},
8282
}),
8383
],
84-
require.resolve('@swmansion/t-rex-ui/preset')
84+
require.resolve('@swmansion/t-rex-ui/preset'),
8585
],
8686

8787
themeConfig:
@@ -104,7 +104,7 @@ const config = {
104104
},
105105
items: [
106106
{
107-
to: 'docs/fundamentals/introduction',
107+
to: 'docs/fundamentals/getting-started',
108108
activeBasePath: 'docs',
109109
label: 'Docs',
110110
position: 'right',

0 commit comments

Comments
 (0)