chourobin
11/22/2015 - 4:56 PM

React Native - Detect Double Tap

React Native - Detect Double Tap

var Index = React.createClass({

  getInitialState: function () {
    return {
      lastPress: 0
    }
  },

  onPress: function () {
    var delta = new Date().getTime() - this.state.lastPress;

    if(delta < 200) {
      // double tap happend
    }

    this.setState({
      lastPress: new Date().getTime()
    })
  },

  render: function() {
    return (
      <TouchableHighlight onPress={this.onPress}></TouchableHighlight>
    )
  }
});