Skip to content

Commit d2cbb50

Browse files
authored
Fix hasWorkletEventHandlers (#3758)
## 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>
1 parent 6605a36 commit d2cbb50

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/react-native-gesture-handler/src/v3/hooks/utils/reanimatedUtils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import RNGestureHandlerModule from '../../../RNGestureHandlerModule';
22
import { Reanimated } from '../../../handlers/gestures/reanimatedWrapper';
3-
import { BaseGestureConfig, SharedValue, SharedValueOrT } from '../../types';
3+
import {
4+
BaseGestureConfig,
5+
GestureCallbacks,
6+
SharedValue,
7+
SharedValueOrT,
8+
} from '../../types';
49
import { HandlerCallbacks } from './propsWhiteList';
510

611
// Variant of djb2 hash function.
@@ -88,9 +93,8 @@ export function hasWorkletEventHandlers<THandlerData, TConfig>(
8893
config: BaseGestureConfig<THandlerData, TConfig>
8994
) {
9095
return Object.entries(config).some(
91-
(key, value) =>
92-
(key as keyof BaseGestureConfig<THandlerData, TConfig>) in
93-
HandlerCallbacks &&
96+
([key, value]) =>
97+
HandlerCallbacks.has(key as keyof GestureCallbacks<unknown>) &&
9498
typeof value === 'function' &&
9599
'__workletHash' in value
96100
);

0 commit comments

Comments
 (0)