简体   繁体   English

React Native相当于mousedown

[英]React Native equivalent to mousedown

If I'm making a website, I can use a mousedown event to trigger something when the mouse button is pressed (and not yet released). 如果要创建网站,则可以使用mousedown事件在按下鼠标按钮(尚未释放)时触发某些事件。

In React Native, I've got a TouchableHighlight and can register an onPress callback, but this only triggers when I release my finger from the button. 在React Native中,我有一个TouchableHighlight并可以注册一个onPress回调,但是只有当我从按钮上松开手指时才会触发。

Is there a way to trigger as soon as a finger touches a button, rather than only when the finger is released? 有没有一种方法可以在手指触摸按钮时立即触发,而不是仅在手指松开时触发?

Solved shortly afterwards! 此后不久解决! The onResponderStart prop is what I needed. 我需要onResponderStart道具。 This isn't actually documented in the gesture responder system docs , but it seems to work for me! 手势响应器系统文档中实际上没有对此进行记录,但是它似乎对我有用!

<View onStartShouldSetResponder={() => true}
      onResponderStart={calledWhenTheTouchStarts}>

    <Text>Press Me!</Text>

</View>

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

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