javascriptiosreact-nativetouchablehighlight

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).

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.

Is there a way to trigger as soon as a finger touches a button, rather than only when the finger is released?


Solution

  • Solved shortly afterwards! The onResponderStart prop is what I needed. 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>