Skip to content

Commit 5f998f4

Browse files
committed
Add StateManager page
1 parent e06ad48 commit 5f998f4

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
id: state-manager
3+
title: State manager
4+
sidebar_label: State manager
5+
sidebar_position: 6
6+
---
7+
8+
RNGH3 allows to manually control gestures lifecycle by using `GestureStateManager`.
9+
10+
## State management
11+
12+
Manual state management is based on `handlerTag`. There are two ways of manual state control.
13+
14+
### Inside gesture definition
15+
16+
If you want to manipulate gesture's state in its callbacks, you can get `handlerTag` from event parameter.
17+
18+
```tsx {3}
19+
const longPress = useLongPressGesture({
20+
onTouchesDown: (e) => {
21+
GestureStateManager.activate(e.handlerTag);
22+
},
23+
onActivate: () => {
24+
console.log('LongPress activated!');
25+
},
26+
});
27+
```
28+
29+
### Outside gesture definition
30+
31+
If you want to control gesture lifecycle outside of it, you can use `tag` from created gesture object.
32+
33+
```tsx {9}
34+
const longPress = useLongPressGesture({
35+
onActivate: () => {
36+
console.log('LongPress activated!');
37+
},
38+
});
39+
40+
const pan = usePanGesture({
41+
onBegin: () => {
42+
GestureStateManager.activate(longPress.tag);
43+
},
44+
});
45+
```
46+
47+
## Methods
48+
49+
### begin
50+
51+
```tsx
52+
begin: (handlerTag: number) => void;
53+
```
54+
55+
Triggers [`onBegin`](/docs/fundamentals/callbacks-events#onbegin) callback on gesture with specified `handlerTag`.
56+
57+
### activate
58+
59+
```tsx
60+
activate: (handlerTag: number) => void;
61+
```
62+
63+
Triggers [`onActivate`](/docs/fundamentals/callbacks-events#onactivate) callback on gesture with specified `handlerTag`.
64+
65+
### deactivate
66+
67+
```tsx
68+
deactivate: (handlerTag: number) => void;
69+
```
70+
71+
Triggers first [`onDeactivate`](/docs/fundamentals/callbacks-events#ondeactivate), then [`onFinalize`](/docs/fundamentals/callbacks-events#onfinalize) callbacks on gesture with specified `handlerTag`.
72+
73+
### fail
74+
75+
```tsx
76+
fail: (handlerTag: number) => void;
77+
```
78+
79+
Triggers [`onFinalize`](/docs/fundamentals/callbacks-events#onfinalize) callback on gesture with specified `handlerTag`. If gesture had activated, it will also trigger [`onDeactivate`](/docs/fundamentals/callbacks-events#ondeactivate) callback.

0 commit comments

Comments
 (0)