我有3个简单的React组件-
首先是实际 View (让我们将此屏幕命名为A)-
return(
<ImageBackground
...
>
<ScrollView>
<ChildButton
onPress={this.someFunction.bind(this)}
/>
</ScrollView>
</ImageBackground>
)
然后是ChildButton组件---
return(
<ChildButton>
<Button
style={...someStyleObject}
onPress={this.props.onPress}
>
</Button>
</ChildButton>
)
然后有Button组件---
return (
<TouchableOpacity
onPress={this.props.onPress}
>
{this.props.children}
</TouchableOpacity>
)
这里的主要问题是我的onPress没有从屏幕A调用,仅在Android上。在iOS上运行正常。可能的原因是什么?
注意:我已经将控制台放入ChildButton和Button组件中,并且它们没有被打印出来。
最佳答案
我不小心从“react-native-gesture-handler”而不是“react-native”导入了TouchableOpacity
时遇到了这个问题。如果您是这种情况,请进行更改,以便从“react-native”导入TouchableOpacity
并从“react-native-gesture-handler”中删除导入,它应该可以工作!
关于android - TouchableOpacity onPress在Android上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51282264/