Skip to content

Commit d4b7ebe

Browse files
authored
Fix ConcurrentModificationException (#3691)
## Description Currently in `NativeDetector` on `android` we have: ```kt fun onViewDrop() { val registry = RNGestureHandlerModule.registries[moduleId] ?: throw Exception("Tried to access a non-existent registry") for (tag in attachedHandlers) { registry.detachHandler(tag) attachedHandlers.remove(tag) } } ``` Under some circumstances (I've managed to reproduce it on my branch with gesture relations) it fails with `ConcurrentModificationException` ## Test plan I'll update when I push my branch to remote. <details> <summary>Tested on the following code:</summary> ```ts import * as React from 'react'; import { Animated, Button, useAnimatedValue } from 'react-native'; import { GestureHandlerRootView, NativeDetector, useSimultaneous, useGesture, useExclusive, useRace, } from 'react-native-gesture-handler'; export default function App() { const [visible, setVisible] = React.useState(true); const value = useAnimatedValue(0); const event = Animated.event( [{ nativeEvent: { handlerData: { translationX: value } } }], { useNativeDriver: true, } ); const tap1 = useGesture('TapGestureHandler', { onEnd: () => { 'worklet'; console.log('Tap 1'); }, numberOfTaps: 1, }); const tap2 = useGesture('TapGestureHandler', { onEnd: () => { 'worklet'; console.log('Tap 2'); }, numberOfTaps: 2, }); const pan1 = useGesture('PanGestureHandler', { onUpdate: (e) => { 'worklet'; console.log('Pan 1'); }, }); const pan2 = useGesture('PanGestureHandler', { onUpdate: (e) => { 'worklet'; console.log('Pan 2'); }, }); // const composedGesture = useExclusive(tap2, tap1); const composedGesture = useRace(pan1, pan2); // const composedGesture = useExclusive(tap1, useSimultaneous(pan1, pan2)); return ( <GestureHandlerRootView style={{ flex: 1, backgroundColor: 'white', paddingTop: 8 }}> <Button title="Toggle visibility" onPress={() => { setVisible(!visible); }} /> {visible && ( <NativeDetector gesture={composedGesture}> <Animated.View style={[ { width: 150, height: 150, backgroundColor: 'blue', opacity: 0.5, borderWidth: 10, borderColor: 'green', marginTop: 20, marginLeft: 40, }, { transform: [{ translateX: value }] }, ]} /> </NativeDetector> )} </GestureHandlerRootView> ); } ``` </details>
1 parent 326b21a commit d4b7ebe

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/react/RNGestureHandlerDetectorView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
128128
val registry = RNGestureHandlerModule.registries[moduleId]
129129
?: throw Exception("Tried to access a non-existent registry")
130130

131-
for (tag in attachedHandlers) {
131+
for (tag in attachedHandlers.toMutableSet()) {
132132
registry.detachHandler(tag)
133133
attachedHandlers.remove(tag)
134134
}

0 commit comments

Comments
 (0)