Commit b60257b
Remove begin from StateManager (#4024)
## Description
We realised that there is no real use case for allowing to state manage
gestures which did not receive touches. Thus we decided to remove the
function `GestureStateManager.begin()` altogether, as if gesture had
received touches it's state is set to begun. Additonally StateManager
will no longer force going through begin state in activate, thus if we
attempt to use state manager to activate a non begun gesture it won't
activate.
## Test plan
Tested on the following example
<details>
```tsx
import { COLORS, commonStyles } from '../common-app/src/common';
import React from 'react';
import { View } from 'react-native';
import {
GestureHandlerRootView,
GestureDetector,
useLongPressGesture,
GestureStateManager,
useSimultaneousGestures,
usePanGesture,
useManualGesture,
} from 'react-native-gesture-handler';
import Animated, {
useAnimatedStyle,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
export default function TwoPressables() {
const isActivated = [useSharedValue(0), useSharedValue(0)];
const lp1 = useLongPressGesture({
onBegin: () => {
'worklet';
console.log("other begin");
},
onActivate: () => {
'worklet';
isActivated[0].value = 1;
console.log(`Box 1: long pressed`);
},
onFinalize: () => {
'worklet';
console.log("other finalized")
isActivated[0].value = 0;
},
disableReanimated: true,
minDuration: 1000000
})
const lp2 = useManualGesture({
onTouchesDown: () => {
console.log("touches down")
},
onTouchesUp: (e) => {
console.log("touches up")
GestureStateManager.deactivate(e.handlerTag)
},
onActivate: () => {
'worklet';
isActivated[1].value = 1;
GestureStateManager.activate(lp1.handlerTag);
console.log(`Box 2: long pressed`);
},
onFinalize: () => {
'worklet';
console.log("fhduifhuifhuiwefhuf")
isActivated[1].value = 0;
},
disableReanimated: true,
})
const pan = usePanGesture({
onActivate: () => {
'worklet';
GestureStateManager.activate(lp2.handlerTag);
}
})
const g2 = useSimultaneousGestures(lp2, pan);
const gestures = []
gestures[0] = lp1;
gestures[1] = g2;
const colors = [COLORS.PURPLE, COLORS.NAVY, COLORS.GREEN, COLORS.RED];
function Box({ index }: { index: number }) {
const animatedStyle = useAnimatedStyle(() => ({
opacity: isActivated[index].value === 1 ? 0.5 : 1,
transform: [
{ scale: withTiming(isActivated[index].value === 1 ? 0.95 : 1) },
],
}));
return (
<GestureDetector gesture={gestures[index]}>
<Animated.View
style={[
commonStyles.box,
{ backgroundColor: colors[index] },
animatedStyle,
]}
/>
</GestureDetector>
);
}
return (
<GestureHandlerRootView>
<View style={commonStyles.centerView}>
<Box index={0} />
<Box index={1} />
</View>
</GestureHandlerRootView>
);
}
```
</details>
---------
Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>1 parent 0e91d90 commit b60257b
File tree
8 files changed
+15
-44
lines changed- packages
- docs-gesture-handler/docs/fundamentals
- react-native-gesture-handler
- android/src/main/java/com/swmansion/gesturehandler/react
- apple
- src
- v3
- web/handlers
- skills/gesture-handler-3-migration
8 files changed
+15
-44
lines changedLines changed: 4 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
| |||
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | 186 | | |
191 | 187 | | |
192 | 188 | | |
| |||
Lines changed: 4 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
155 | 152 | | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | 153 | | |
160 | 154 | | |
161 | 155 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
229 | | - | |
230 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| |||
Lines changed: 0 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 23 | | |
30 | 24 | | |
31 | 25 | | |
| |||
Lines changed: 0 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | 18 | | |
29 | 19 | | |
30 | 20 | | |
31 | 21 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | 22 | | |
38 | 23 | | |
39 | 24 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
| |||
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
| 83 | + | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
0 commit comments