How to catch the tap down event on React Native?

2020-04-07 02:51发布

I want to catch the event when a user taps on the view. Currently, I use the TouchableXXX components to catch user onPress (seems like onPress catches the onTapDown event only).

2条回答
smile是对你的礼貌
2楼-- · 2020-04-07 03:20

The accepted answer does not work anymore. The correct way is to use Touchable's onPressIn()

https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html#onpressin

查看更多
别忘想泡老子
3楼-- · 2020-04-07 03:27

You can set onTouchStart and onTouchEnd handlers on any View via props, for example:

<View onTouchStart={() => this.doSomething()} />

For general information about RN touches see the Handling Touches guide. In case you need a more complex, or custom touch handling, see the Gesture Responder System guide.

查看更多
登录 后发表回答