【发布时间】:2017-11-19 10:53:50
【问题描述】:
尽管本文档 (https://facebook.github.io/react-native/docs/gesture-responder-system.html) 指出,触摸事件会传递给子级并且仅由父级使用,但如果子级没有对事件做出反应,我将面临一个问题,即 TouchableOpacity嵌套在另一个 TouchableOpacity 中对触摸没有正确反应。
我的结构如下
<ScrollView>
<TouchableOpacity onPress={() => console.log('This is printed always')}>
<View>
<Text>I can click here</Text>
<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>
</View>
</TouchableOpacity>
</ScrollView>
TouchableOpacitys 中的 Button 也是如此:点击 Button 会调用父 TouchableOpacity 的 onPress 方法
我在监督什么吗?
【问题讨论】:
-
我在使用来自
react-native的TouchableOpacity 和来自react-native-gesture-handler的另一个组合时遇到了这个问题。当使用相同的两次时,它会按预期工作,孩子是唯一触发新闻事件的人。 -
@EliezerSteinbock 谢谢...我遇到了和你提到的一样的问题。
标签: android react-native touchableopacity