我需要监听 React Native View 的触摸事件并在回调中执行一些操作。我无法以简单的方式做到这一点。我能找到的唯一解决方法是使用 Pan Responder 并使用 onResponderGrant
回调。想知道是否有更简单的方法来监听触摸事件,类似于 onPress
。
最佳答案
您可以将 TouchableOpacity
用作提供可触摸反馈的 View
。例如
<TouchableOpacity
onPress = {() => function()}
onLongPress = {() => longerFunction()}
style = {{these can be the same as a normal View}}>
</TouchableOpacity>
也可以使用TouchableHighlight
和TouchableWithoutFeedback
,分别提供了变暗的onPress效果和无效果。
关于javascript - 如何在 React Native 中监听触摸事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46903939/