Skip to content

Instantly share code, notes, and snippets.

@smitroshin
Created May 15, 2020 14:12
Show Gist options
  • Save smitroshin/98834a303c18d8434c38351b8cace23f to your computer and use it in GitHub Desktop.
Save smitroshin/98834a303c18d8434c38351b8cace23f to your computer and use it in GitHub Desktop.
React - long press
class App extends Component {
constructor() {
super()
this.handleButtonPress = this.handleButtonPress.bind(this)
this.handleButtonRelease = this.handleButtonRelease.bind(this)
}
handleButtonPress () {
this.buttonPressTimer = setTimeout(() => alert('long press activated'), 1500);
}
handleButtonRelease () {
clearTimeout(this.buttonPressTimer);
}
render() {
return (
<div
onTouchStart={this.handleButtonPress}
onTouchEnd={this.handleButtonRelease}
onMouseDown={this.handleButtonPress}
onMouseUp={this.handleButtonRelease}
onMouseLeave={this.handleButtonRelease}>
Button
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment