-
-
Save jqn/af46d85cf92a03694c6603d7b7c84f5f to your computer and use it in GitHub Desktop.
Double tap gesture recognition for React Native.
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
const DOUBLE_PRESS_DELAY = 300; | |
// ... | |
/** | |
* Double Press recognition | |
* @param {Event} e | |
*/ | |
handleImagePress(e) { | |
const now = new Date().getTime(); | |
console.log(e); | |
if (this.lastImagePress && (now - this.lastImagePress) < DOUBLE_PRESS_DELAY) { | |
delete this.lastImagePress; | |
this.handleImageDoublePress(e); | |
} | |
else { | |
this.lastImagePress = now; | |
} | |
} | |
handleImageDoublePress(e) { | |
console.log('double press activated!'); | |
} | |
// ... | |
<TouchableWithoutFeedback onPress={this.handleImagePress}> | |
<Image style={styles.verseArtwork} source={verse.artwork} /> | |
</TouchableWithoutFeedback> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment