1
- import { useEffect , useRef } from 'react' ;
1
+ import { useEffect , useRef , useCallback } from 'react' ;
2
2
import { View } from 'react-native' ;
3
3
import RNGestureHandlerModule from '../RNGestureHandlerModule.web' ;
4
4
import { ActionType } from '../ActionType' ;
@@ -15,8 +15,20 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
15
15
const viewRef = useRef ( null ) ;
16
16
const propsRef = useRef < GestureHandlerDetectorProps > ( props ) ;
17
17
const oldHandlerTags = useRef < Set < number > > ( new Set < number > ( ) ) ;
18
+ const oldDispatchesAnimatedEvents = useRef < boolean > ( null ) ;
18
19
19
- const attachHandlers = ( ) => {
20
+ const detachHandlers = useCallback ( ( ) => {
21
+ handlerTags . forEach ( ( tag ) => {
22
+ RNGestureHandlerModule . detachGestureHandler ( tag ) ;
23
+ } ) ;
24
+ } , [ handlerTags ] ) ;
25
+
26
+ const attachHandlers = useCallback ( ( ) => {
27
+ if ( oldDispatchesAnimatedEvents . current !== dispatchesAnimatedEvents ) {
28
+ // We reattach handlers, if the action type changes
29
+ oldHandlerTags . current = new Set < number > ( ) ;
30
+ detachHandlers ( ) ;
31
+ }
20
32
const currentHandlerTags = new Set ( handlerTags ) ;
21
33
const newHandlerTags = currentHandlerTags . difference (
22
34
oldHandlerTags . current
@@ -32,13 +44,7 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
32
44
) ;
33
45
} ) ;
34
46
oldHandlerTags . current = currentHandlerTags ;
35
- } ;
36
-
37
- const detachHandlers = ( ) => {
38
- handlerTags . forEach ( ( tag ) => {
39
- RNGestureHandlerModule . detachGestureHandler ( tag ) ;
40
- } ) ;
41
- } ;
47
+ } , [ handlerTags , dispatchesAnimatedEvents , detachHandlers ] ) ;
42
48
43
49
useEffect ( ( ) => {
44
50
attachHandlers ( ) ;
0 commit comments