@@ -10,11 +10,7 @@ import {
1010} from '../types' ;
1111import { DetectorContext } from './useDetectorContext' ;
1212import { Reanimated } from '../../handlers/gestures/reanimatedWrapper' ;
13- import {
14- configureRelations ,
15- getHandlerTag ,
16- invokeDetectorEvent ,
17- } from './utils' ;
13+ import { configureRelations } from './utils' ;
1814import { isComposedGesture } from '../hooks/utils/relationUtils' ;
1915
2016export interface NativeDetectorProps {
@@ -77,19 +73,53 @@ export function NativeDetector({ gesture, children }: NativeDetectorProps) {
7773
7874 const handleGestureEvent = ( key : keyof GestureEvents < unknown > ) => {
7975 return ( e : GestureHandlerEvent < unknown > ) => {
80- const handlerTag = getHandlerTag ( e ) ;
81-
82- const method = ! logicMethods . current . has ( handlerTag )
83- ? gesture . gestureEvents [ key ]
84- : logicMethods . current . get ( handlerTag ) ?. current ?. [ key ] ;
85-
86- invokeDetectorEvent (
87- method as ( e : GestureHandlerEvent < unknown > ) => void ,
88- e
89- ) ;
76+ if ( gesture . gestureEvents [ key ] ) {
77+ gesture . gestureEvents [ key ] ( e ) ;
78+ }
79+
80+ logicMethods . current . forEach ( ( ref ) => {
81+ const method = ref . current ?. [ key ] ;
82+ if ( method ) {
83+ method ( e ) ;
84+ }
85+ } ) ;
9086 } ;
9187 } ;
9288
89+ const getHandlers = useCallback (
90+ ( key : keyof GestureEvents < unknown > ) => {
91+ const handlers : ( ( e : GestureHandlerEvent < unknown > ) => void ) [ ] = [ ] ;
92+
93+ if ( gesture . gestureEvents [ key ] ) {
94+ handlers . push (
95+ gesture . gestureEvents [ key ] as (
96+ e : GestureHandlerEvent < unknown >
97+ ) => void
98+ ) ;
99+ }
100+
101+ logicMethods . current . forEach ( ( ref ) => {
102+ const handler = ref . current ?. [ key ] ;
103+ if ( handler ) {
104+ handlers . push ( handler as ( e : GestureHandlerEvent < unknown > ) => void ) ;
105+ }
106+ } ) ;
107+
108+ return handlers ;
109+ } ,
110+ [ logicChildren , gesture . gestureEvents ]
111+ ) ;
112+
113+ const reanimatedEventHandler = Reanimated ?. useComposedEventHandler (
114+ getHandlers ( 'onReanimatedUpdateEvent' )
115+ ) ;
116+ const reanimedStateChangeHandler = Reanimated ?. useComposedEventHandler (
117+ getHandlers ( 'onReanimatedStateChange' )
118+ ) ;
119+ const reanimatedTouchEventHandler = Reanimated ?. useComposedEventHandler (
120+ getHandlers ( 'onReanimatedTouchEvent' )
121+ ) ;
122+
93123 return (
94124 < DetectorContext . Provider value = { { register, unregister } } >
95125 < NativeDetectorComponent
@@ -108,17 +138,11 @@ export function NativeDetector({ gesture, children }: NativeDetectorProps) {
108138 'onGestureHandlerTouchEvent'
109139 ) }
110140 // @ts -ignore This is a type mismatch between RNGH types and RN Codegen types
111- onGestureHandlerReanimatedStateChange = { handleGestureEvent (
112- 'onReanimatedStateChange'
113- ) }
141+ onGestureHandlerReanimatedStateChange = { reanimatedEventHandler }
114142 // @ts -ignore This is a type mismatch between RNGH types and RN Codegen types
115- onGestureHandlerReanimatedEvent = { handleGestureEvent (
116- 'onReanimatedUpdateEvent'
117- ) }
143+ onGestureHandlerReanimatedEvent = { reanimedStateChangeHandler }
118144 // @ts -ignore This is a type mismatch between RNGH types and RN Codegen types
119- onGestureHandlerReanimatedTouchEvent = { handleGestureEvent (
120- 'onReanimatedTouchEvent'
121- ) }
145+ onGestureHandlerReanimatedTouchEvent = { reanimatedTouchEventHandler }
122146 moduleId = { globalThis . _RNGH_MODULE_ID }
123147 handlerTags = { isComposedGesture ( gesture ) ? gesture . tags : [ gesture . tag ] }
124148 style = { styles . detector }
0 commit comments