我面临一个奇怪的问题。在我的反应本机应用程序中,如果我设置onPress
事件至View
它没有被触发,但如果我将其设置为Text
inside View
,它着火了。我在这里缺少什么?
<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版本
您可以使用TouchableOpacity
for onPress
事件。View
不提供onPress
prop.
<TouchableOpacity style={{backgroundColor: "red", padding: 20}} onPress={()=> {
console.log('does not work');
}
}>
<Text>X</Text>
</TouchableOpacity>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)