Commit d2cbb50
authored
Fix
## Description
This PR fixes incorrect implementation of `hasWorkletEventHandlers`
function. Namely:
1. Changes `in` to `has`, as `in` cannot be used to check if `Set`
contains given element;
2. Correctly wraps `some` parameter into `[]` - earlier `value` was
actually an index.
This problems resulted in callbacks being run on `JS`, even when they
should be run on `UI`.
## Test plan
<details>
<summary>Tested on the following code:</summary>
```tsx
import * as React from 'react';
import { Animated, Button } from 'react-native';
import {
GestureHandlerRootView,
NativeDetector,
usePan,
} from 'react-native-gesture-handler';
import { getRuntimeKind } from 'react-native-worklets';
export default function App() {
const [visible, setVisible] = React.useState(true);
const gesture = usePan({
onUpdate: () => {
'worklet';
console.log(getRuntimeKind());
},
});
return (
<GestureHandlerRootView
style={{ flex: 1, backgroundColor: 'white', paddingTop: 8 }}>
<Button
title="Toggle visibility"
onPress={() => {
setVisible(!visible);
}}
/>
{visible && (
<NativeDetector gesture={gesture}>
<Animated.View
style={[
{
width: 150,
height: 150,
backgroundColor: 'blue',
opacity: 0.5,
borderWidth: 10,
borderColor: 'green',
marginTop: 20,
marginLeft: 40,
},
]}
/>
</NativeDetector>
)}
</GestureHandlerRootView>
);
}
```
</details>hasWorkletEventHandlers (#3758)1 parent 6605a36 commit d2cbb50
File tree
1 file changed
+8
-4
lines changed- packages/react-native-gesture-handler/src/v3/hooks/utils
1 file changed
+8
-4
lines changedLines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
| |||
88 | 93 | | |
89 | 94 | | |
90 | 95 | | |
91 | | - | |
92 | | - | |
93 | | - | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
| |||
0 commit comments