Created
May 15, 2020 14:12
-
-
Save smitroshin/98834a303c18d8434c38351b8cace23f to your computer and use it in GitHub Desktop.
React - long press
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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