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: packages/docs-gesture-handler/docs/guides/quickstart/index.md
+74-17Lines changed: 74 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,45 +12,102 @@ import Step3 from './\_steps/step3.md';
12
12
import Step4 from './\_steps/step4.md';
13
13
import Step5 from './\_steps/step5.md';
14
14
15
-
RNGH2 provides much simpler way to add gestures to your app. All you need to do is wrap the view that you want your gesture to work on with [`GestureDetector`](/docs/fundamentals/gesture-detectors#gesture-detector), define the gesture and pass it to detector. That's all!
15
+
RNGH3 offers a straightforward way to add gestures to your app. Simply wrap your target view with the [GestureDetector](/docs/fundamentals/gesture-detectors#gesture-detector) component, define your gesture, and pass it in. That’s it!
16
16
17
-
To demonstrate how you would use the new API, let's make a simple app where you can drag a ball around. You will need to add `react-native-gesture-handler` (for gestures) and `react-native-reanimated` (for animations) modules.
17
+
To see the new API in action, let's build a simple app where you can drag a ball around the screen. To follow along, you'll need both `react-native-gesture-handler` (to handle gestures) and [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/) (to handle the animations).
18
18
19
19
<Steptitle="Step 1">
20
-
<div>First let's define styles we will need to make the app:</div>
20
+
<div>Start by defining the basic structure of the application:</div>
21
21
<Step1 />
22
22
</Step>
23
23
24
24
<Steptitle="Step 2">
25
-
<div>Then we can start writing our <code>Ball</code> component:</div>
25
+
<div>
26
+
Next, define the <a href="https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#shared-value">`SharedValues`</a> to track the ball's position and create the animated styles required to position the ball on the screen:
to keep track of the ball position and create animated styles in order to be
36
-
able to position the ball on the screen:
37
-
</div>
32
+
<div>Apply the animated styles to the ball component:</div>
38
33
<Step3 />
39
34
</Step>
40
35
41
36
<Steptitle="Step 4">
42
-
<div>And add it to the ball's styles:</div>
37
+
<div>
38
+
Now, define the <code>Pan</code> gesture logic.
39
+
</div>
43
40
<Step4 />
44
41
</Step>
45
42
46
43
<Steptitle="Step 5">
47
44
<div>
48
-
The only thing left is to define the pan gesture and assign it to the
49
-
detector:
45
+
Finally, wrap the component responsible for rendering the ball with a <code>GestureDetector</code>, and attach the <code>Pan</code> gesture to it:
50
46
</div>
51
47
<Step5 />
52
48
</Step>
53
49
54
-
Note the `start` shared value. We need it to store the position of the ball at the moment we grab it to be able to correctly position it later, because we only have access to translation relative to the starting point of the gesture.
Now you can just add `Ball` component to some view in the app and see the results! (Or you can just check the code [here](https://github.com/software-mansion/react-native-gesture-handler/blob/main/example/src/new_api/velocityTest/index.tsx) and see it in action in the Example app.)
0 commit comments