-
-
Notifications
You must be signed in to change notification settings - Fork 984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Text onPress triggers parent Touchable onPress #3159
Comments
Hi @dragoncodes! Could you please check if using our |
## Description This PR adds `Text` component to **Gesture Handler**. Upon investigating #3159 we decided that it will be better to add our own `Text` component, instead of forcing users to create their own version of `Text` with `NativeViewGestureHandler`. ## Test plan <details> <summary>New example:</summary> ```jsx import { useState } from 'react'; import { StyleSheet } from 'react-native'; import { Text, GestureHandlerRootView, TouchableOpacity, } from 'react-native-gesture-handler'; export default function NestedText() { const [counter, setCounter] = useState(0); return ( <GestureHandlerRootView style={styles.container}> <Text style={{ fontSize: 30 }}>{`Counter: ${counter}`}</Text> <TouchableOpacity onPress={() => { console.log('Touchable'); setCounter((prev) => prev + 1); }}> <Text style={[styles.textCommon, styles.outerText]} onPress={() => { console.log('Outer text'); setCounter((prev) => prev + 1); }}> {'Outer Text '} <Text style={[styles.textCommon, styles.innerText]} onPress={() => { console.log('Nested text'); setCounter((prev) => prev + 1); }}> {'Nested Text'} </Text> </Text> </TouchableOpacity> </GestureHandlerRootView> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 20, }, textCommon: { padding: 10, color: 'white', }, outerText: { fontSize: 30, borderWidth: 2, backgroundColor: '#131313', }, innerText: { fontSize: 25, backgroundColor: '#F06312', }, }); ``` </details>
I gave the changes in #3202 a try in my iOS app. While the sample code in the PR mostly works (on iOS the |
To clarify the above: this works as expected with React Native components, but does not behave the same with RNGH. I have |
Thanks for your feedback @mhoran. I'll look into it. I'm closing this issue as it seems to be resolved. In the meantime, could you open new one regarding problems that you've mentioned? |
Thanks. I have opened a new issue here: #3331. |
Description
When a
Text
withonPress
is a child of anyTouchable
(Opacity, Highlight, WithoutFeedback), when tapping on theText
theonPress
of theTouchable
parent is also triggered.*Only seen on Android
Note: On iOS only the parent
Touchable#onPress
is triggered, but if theText
is wrapped inNativeViewGestureHandler
-> only theText#onPress
is calledSteps to reproduce
Current behavior:
Counter is incremented by 2
Expected behaviour:
Counter is incremented by 1
Preview:
Note: Not sure what runtime snacks use, but also tested with
[email protected]
,[email protected]
, Hermes on a real deviceSnack or a link to a repository
https://snack.expo.dev/@dragoncodes/rngh-multi-onpress-repro?platform=android
Gesture Handler version
2.16.2
React Native version
0.74.1
Platforms
Android
JavaScript runtime
Hermes
Workflow
Expo bare workflow
Architecture
Fabric (New Architecture)
Build type
Release mode
Device
Real device
Device model
Samsung Galaxy Fold 4
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: