react-native-gesture-handler: Nested touchables don't work correctly on Android
Expected Behavior
Current Behavior
Description
When you have nested touchables from react-native-gesture-handler
and press the inner touchable, the outer one also gets pressed.
Reproduction (Android): https://snack.expo.io/@brunolemos/rngh-nested-touchable-android-bug
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 19
- Comments: 37 (10 by maintainers)
Links to this issue
Commits related to this issue
- [Temp][Android] Disable nested touchables inside card https://github.com/kmagiera/react-native-gesture-handler/issues/784 — committed to khadorkin/devhub by brunolemos 5 years ago
- [Android] Fix nested touchable issue + Enable card items press-to-filter https://github.com/kmagiera/react-native-gesture-handler/issues/784 https://github.com/kmagiera/react-native-gesture-handler/... — committed to khadorkin/devhub by brunolemos 5 years ago
- Fix nested touchables on Android (#1601) Builds upon https://github.com/software-mansion/react-native-gesture-handler/pull/486 in order to fix https://github.com/software-mansion/react-native-gesture... — committed to software-mansion/react-native-gesture-handler by j-piasecki 3 years ago
- Fix nested touchables on Android (#1601) Builds upon https://github.com/software-mansion/react-native-gesture-handler/pull/486 in order to fix https://github.com/software-mansion/react-native-gesture... — committed to wordpress-mobile/react-native-gesture-handler by j-piasecki 3 years ago
Passing
disallowInterruption={true}
to the touchable should fix this.Should this be enabled by default in GenericTouchable?
I tried TouchableOpacity from ‘react-native’ lib it works fine
I am still having this problem on 1.6.1
1.8.0 same problem
Any fix for this? I am experiencing it as well. Upgraded our
react-native-gesture-handler
version to 1.4.1 and still seeing the same problem. Everything works fine in iOS but Android is trigger both onPress events for the two separate touchable events.I think this issue also affects if you try to use
createNativeStackNavigator
from react-native-screens, because when I set that stack navigator all my Touchables from react-native-gesture-handler stops workingI update patch to working with react-native-gesture-handler 1.6.1
I switched to using the Button components which have basically all the feedback styles you’d want but more importantly they work when nested.
still an issue in
^1.9.0
.same issue 1.9.0 in android touch events bubble inside multiple overlapping touch areas
for Android, import the outer component from ‘react-native’ import { TouchableOpacity as NativeTouchableOpacity, Platform } from ‘react-native’; import { TouchableOpacity as GHTouchableOpacity } from ‘react-native-gesture-handler’ const TouchableOpacity = Platform.OS === ‘ios’ ? GHTouchableOpacity : NativeTouchableOpacity;
#486 fixes this bug 🎉
Here’s the patch that can be applied using patch-package:
patches/react-native-gesture-handler+1.5.2.patch
Seems like the issue happens on web too. I made a snack repro that shows the different behaviour with Touchable from react-native and react-native-gesture-handler. https://snack.expo.dev/JEnwHDo1h