Skip to content

Commit 864cffe

Browse files
authored
[android] dont cancel manually activated gestures (#4011)
## Description Manually handled gestures were being cancelled when another gesture received an event. This PR fixes the issue. ## Test plan Tested on slightly modified version of StateManager example: <details> ```tsx import { COLORS, commonStyles } from '../../../common'; import React from 'react'; import { View } from 'react-native'; import { LongPressGestureConfig } from 'react-native-gesture-handler'; import { GestureHandlerRootView, GestureDetector, useLongPressGesture, GestureStateManager, LongPressGesture, } from 'react-native-gesture-handler'; import Animated, { useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated'; export default function TwoPressables() { const isActivated = [ useSharedValue(0), useSharedValue(0), useSharedValue(0), useSharedValue(0), ]; const gestures: LongPressGesture[] = []; const createGestureConfig = (index: number): LongPressGestureConfig => ({ onActivate: () => { 'worklet'; isActivated[index].value = 1; console.log(`Box ${index}: long pressed`); const nextIndex = index + 1; if (nextIndex < gestures.length) { const nextGesture = gestures[nextIndex]; if (nextGesture) { GestureStateManager.activate(nextGesture.handlerTag); } } }, onFinalize: (_, success) => { 'worklet'; isActivated[index].value = 0; console.log(`Box ${index}: finalised gesture, `, success); const nextIndex = index + 1; if (nextIndex < gestures.length) { const nextGesture = gestures[nextIndex]; if (nextGesture) { GestureStateManager.deactivate(nextGesture.handlerTag); } } }, disableReanimated: true, }); const g0 = useLongPressGesture(createGestureConfig(0)); const g1 = useLongPressGesture(createGestureConfig(1)); const g2 = useLongPressGesture(createGestureConfig(2)); const g3 = useLongPressGesture(createGestureConfig(3)); gestures[0] = g0; gestures[1] = g1; gestures[2] = g2; gestures[3] = g3; const colors = [COLORS.PURPLE, COLORS.NAVY, COLORS.GREEN, COLORS.RED]; function Box({ index }: { index: number }) { const animatedStyle = useAnimatedStyle(() => ({ opacity: isActivated[index].value === 1 ? 0.5 : 1, transform: [ { scale: withTiming(isActivated[index].value === 1 ? 0.95 : 1) }, ], })); return ( <GestureDetector gesture={gestures[index]}> <Animated.View style={[ commonStyles.box, { backgroundColor: colors[index] }, animatedStyle, ]} /> </GestureDetector> ); } return ( <GestureHandlerRootView> <View style={commonStyles.centerView}> <Box index={0} /> <Box index={1} /> <Box index={2} /> <Box index={3} /> </View> </GestureHandlerRootView> ); } ``` </details>
1 parent af8b121 commit 864cffe

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class GestureHandlerOrchestrator(
287287
}
288288

289289
private fun deliverEventToGestureHandler(handler: GestureHandler, sourceEvent: MotionEvent) {
290-
if (!isViewAttachedUnderWrapper(handler.view)) {
290+
if (!isViewAttachedUnderWrapper(handler.view ?: handler.hostDetectorView)) {
291291
handler.cancel()
292292
return
293293
}

0 commit comments

Comments
 (0)