Skip to content

Commit 2d3116e

Browse files
authored
Change logic of worklet detection in config (#3745)
## Description This PR fixes issue where using `Animated.Event` without `worklet` callbacks was throwing error. This was because current implementation of `hasWorkletEventHandlers` was checking all functions present in `config`, including `changeEventCalculator` (which is in fact `worklet`). > [!NOTE] > It previously contained #3748 ## Test plan Tested on the current `basic-example` app
1 parent 470ed63 commit 2d3116e

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
SingleGestureName,
1515
InternalConfigProps,
1616
HandlersPropsWhiteList,
17+
GestureCallbacks,
1718
} from '../types';
1819
import { GestureTouchEvent } from '../../handlers/gestureHandlerCommon';
1920
import { tagMessage } from '../../utils';
@@ -110,8 +111,9 @@ const allowedNativeProps = new Set<
110111
'changeEventCalculator',
111112
]);
112113

113-
const PropsToFilter = new Set<BaseGestureConfig<unknown, unknown>>([
114-
// Callbacks
114+
export const HandlerCallbacks = new Set<
115+
keyof Required<GestureCallbacks<unknown>>
116+
>([
115117
'onBegin',
116118
'onStart',
117119
'onUpdate',
@@ -121,6 +123,10 @@ const PropsToFilter = new Set<BaseGestureConfig<unknown, unknown>>([
121123
'onTouchesMove',
122124
'onTouchesUp',
123125
'onTouchesCancelled',
126+
]);
127+
128+
const PropsToFilter = new Set<BaseGestureConfig<unknown, unknown>>([
129+
...HandlerCallbacks,
124130

125131
// Config props
126132
'changeEventCalculator',

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import RNGestureHandlerModule from '../../../RNGestureHandlerModule';
22
import { Reanimated } from '../../../handlers/gestures/reanimatedWrapper';
33
import { BaseGestureConfig, SharedValue } from '../../types';
4+
import { HandlerCallbacks } from '../utils';
45

56
// Variant of djb2 hash function.
67
// Taken from https://gist.github.com/eplawless/52813b1d8ad9af510d85?permalink_comment_id=3367765#gistcomment-3367765
@@ -77,7 +78,11 @@ export function unbindSharedValues<THandlerData, TConfig>(
7778
export function hasWorkletEventHandlers<THandlerData, TConfig>(
7879
config: BaseGestureConfig<THandlerData, TConfig>
7980
) {
80-
return Object.values(config).some(
81-
(prop) => typeof prop === 'function' && '__workletHash' in prop
81+
return Object.entries(config).some(
82+
(key, value) =>
83+
(key as keyof BaseGestureConfig<THandlerData, TConfig>) in
84+
HandlerCallbacks &&
85+
typeof value === 'function' &&
86+
'__workletHash' in value
8287
);
8388
}

0 commit comments

Comments
 (0)