繁体   English   中英

如何在React Native中收听触摸事件?

[英]How to listen to a touch event in React Native?

我需要监听React Native视图的触摸事件并在回调中执行一些操作。 我无法以一种简单的方式做到这一点。 我找到的唯一解决方法是使用Pan Responder并使用onResponderGrant回调。 想知道是否有一种更简单的方式来听取触摸事件,类似于onPress

您可以将TouchableOpacity用作提供可触摸反馈的View 例如

<TouchableOpacity
    onPress = {() => function()}
    onLongPress = {() => longerFunction()}
    style = {{these can be the same as a normal View}}>
</TouchableOpacity>

您还可以使用TouchableHighlightTouchableWithoutFeedback ,它们分别提供变暗的onPress效果和无效果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM