Commit 8e64fef
authored
[Web] Remove workaround for touch events allowing to change state too soon (#3794)
## Description
Ordering of touch events on the web was mostly aligned with Android. To
unify the ordering across all platforms (along
#3793),
this PR changes it so that `onTouchesDown` is called before `onBegin`
and `onTouchesMove` is called before `onUpdate`.
Another change is enforcing going through `BEGAN` when imperatively
changing the state from `UNDETERMINED` to `ACTIVE`.
And a fix for an issue that came out due to the above changes - when the
discrete gestures were imperatively activated inside `onTouchesDown`,
the order was:
```
Touch down
Gesture begin
Gesture start
Touch cancel
Gesture end
Gesture finalize
Gesture begin
Gesture finalize
```
This was because those gestures transition to the `END` state
immediately after `ACTIVE`, and get reset immediately. Then, the normal
flow resumes, and they go to the `BEGAN` as a result of touch input. To
prevent that, I changed `cleanupFinishedHandlers` to be queued as a
microtask instead of being executed immediately. This should ensure that
it will be called in the same run loop, but after the gesture handles
its state.
## Test plan
Tested on the following code:
```
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
export default function EmptyExample() {
const pan = Gesture.Pan()
.onTouchesDown((e, stateManager) => {
'worklet';
console.log('Touch down');
stateManager.activate();
})
.onTouchesMove(() => {
'worklet';
console.log('Touch move');
})
.onTouchesUp(() => {
'worklet';
console.log('Touch up');
})
.onTouchesCancelled(() => {
'worklet';
console.log('Touch cancel');
})
.onBegin(() => {
'worklet';
console.log('Gesture begin');
})
.onStart((e) => {
'worklet';
console.log('Gesture start');
})
.onEnd(() => {
'worklet';
console.log('Gesture end');
})
.onFinalize(() => {
'worklet';
console.log('Gesture finalize');
});
return (
<View style={styles.container}>
<GestureDetector gesture={pan}>
<View style={{ width: 300, height: 300, backgroundColor: 'green' }} />
</GestureDetector>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
```1 parent ad2029d commit 8e64fef
File tree
11 files changed
+18
-24
lines changed- packages/react-native-gesture-handler/src
- handlers/gestures
- web
- handlers
- tools
11 files changed
+18
-24
lines changedLines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
15 | 24 | | |
16 | 25 | | |
17 | 26 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | 128 | | |
131 | 129 | | |
132 | 130 | | |
| |||
Lines changed: 5 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | | - | |
351 | | - | |
352 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| 373 | + | |
373 | 374 | | |
374 | 375 | | |
375 | 376 | | |
376 | | - | |
377 | | - | |
378 | 377 | | |
379 | 378 | | |
380 | 379 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
96 | 94 | | |
97 | 95 | | |
98 | 96 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | 77 | | |
80 | 78 | | |
81 | 79 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
234 | | - | |
235 | 233 | | |
236 | 234 | | |
237 | 235 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
138 | | - | |
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
| |||
0 commit comments