Commit 802a15b
authored
[General] Fix gestures becoming unresponsive after a fast refresh (#4096)
## Description
Fast refresh was able to make gestures unresponsive - Gesture Handler
uses `useMemo` to store the handler tag, which gets invalidated on the
fast refresh. Reanimated's `useHandler`/`useEvent` preserves their
internal state, and the worklet event handler didn't rebuild. This
caused a gesture with a new tag to use the event handler built for the
previous tag, which was ignoring all incoming events.
This PR fixes this by tracking handler tag changes and rebuilding the
event handler when it changes.
Supersedes
#3997
## Test plan
<details>
<summary>File1.tsx</summary>
```jsx
import React from 'react';
import { View } from 'react-native';
import { GestureDetector, useTapGesture } from 'react-native-gesture-handler';
function Test() {
const gesture = useTapGesture({
onActivate: () => {
console.log('onActivate');
},
});
const COMMENT_THIS = 2;
return (
<GestureDetector gesture={gesture}>
<View style={{ width: 100, height: 100, backgroundColor: 'red' }} />
</GestureDetector>
);
}
export default Test;
```
</details>
<details>
<summary>File2.tsx</summary>
```jsx
import React from 'react';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import Test from './File1';
function Example() {
return (
<GestureHandlerRootView>
<Test />
</GestureHandlerRootView>
);
}
export default Example;
```
</details>
1. Navigate to `File2`
2. Verify that tap works
3. Comment `COMMENT_THIS` and save `File1`
4. Check whether the tap works1 parent ba999e0 commit 802a15b
1 file changed
Lines changed: 23 additions & 7 deletions
Lines changed: 23 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
13 | 19 | | |
14 | 20 | | |
15 | 21 | | |
| |||
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
62 | 82 | | |
63 | 83 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 84 | + | |
| 85 | + | |
70 | 86 | | |
71 | 87 | | |
72 | 88 | | |
| |||
0 commit comments