Commit d4b7ebe
authored
Fix
## 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>ConcurrentModificationException (#3691)1 parent 326b21a commit d4b7ebe
File tree
1 file changed
+1
-1
lines changed- packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react
1 file changed
+1
-1
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
0 commit comments