Stacked TouchableOpacity inside another TouchableOpacity is not clickable

前端 未结 3 690
深忆病人
深忆病人 2021-02-05 10:14

Even though this document (https://facebook.github.io/react-native/docs/gesture-responder-system.html) states, that touch events are passed down to the children and are only con

相关标签:
3条回答
  • 2021-02-05 10:43

    Writing here to make it a little more prominent.

    It could be the nested TouchableOpacity is being imported from something different from the parent one as mentioned by @EliezerSteinbock. This could be quite possible as many of us use auto-imports on visual code or other IDE.

    Sadly I missed her comment the first time round, so hopefully this would help someone else

    0 讨论(0)
  • 2021-02-05 10:58

    You could just use TouchableWithoutFeedback to wrap inner TouchableOpacity.

    Something like:

    <TouchableOpacity onPress={() => console.log('This is printed always')}>
        <View>
            <Text>I can click here</Text>
            <TouchableWithoutFeedback>
                <TouchableOpacity onPress={() => console.log('This is printed never')}>
                    <Text>I can click here but the outer onPress is called instead of the inner one</text>
                </TouchableOpacity>
            </TouchableWithoutFeedback>
        </View>
    </TouchableOpacity>
    
    0 讨论(0)
  • 2021-02-05 11:00

    Change import of Touchable opacity from

    import { TouchableOpacity } from 'react-native-gesture-handler';
    

    To the following and it will now all be fine!

    import { TouchableOpacity } from 'react-native';
    
    0 讨论(0)
提交回复
热议问题