React Native:查看 onPress 不起作用 [英] React Native: View onPress does not work
本文介绍了React Native:查看 onPress 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个奇怪的问题.在我的本机应用程序中,如果我将 onPress
事件设置为 View
它不会被触发但如果我在 中将它设置为
,它会触发.我在这里错过了什么?Text
查看
I'm facing a weird problem. In my react native app, if I set onPress
event to View
it is not triggered but if I set the same to Text
inside View
, it fires. What am I missing here?
<View style={{backgroundColor: "red", padding: 20}}>
<Text onPress={()=> {
console.log('works');
}
}>X</Text>
</View>
<View style={{backgroundColor: "red", padding: 20}} onPress={()=> {
console.log('does not work');
}
}>
<Text>X</Text>
</View>
为什么会这样?这是 React Native 的问题吗?我使用的是 0.43 版
Why is this so? Is this an issue with React Native? I'm using version 0.43
推荐答案
您可以将 TouchableOpacity
用于 onPress
事件.View
不提供 onPress
道具.
You can use TouchableOpacity
for onPress
event.
View
doesn't provide onPress
prop.
<TouchableOpacity style={{backgroundColor: "red", padding: 20}} onPress={()=> {
console.log('does not work');
}
}>
<Text>X</Text>
</TouchableOpacity>
这篇关于React Native:查看 onPress 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文