Skip to content

Instantly share code, notes, and snippets.

@brunotavares
Last active June 4, 2022 17:14
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save brunotavares/3c9a373ba5cd1b4ff28b to your computer and use it in GitHub Desktop.
Save brunotavares/3c9a373ba5cd1b4ff28b to your computer and use it in GitHub Desktop.
Double tap gesture recognition for React Native.
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>
@bispul
Copy link

bispul commented Oct 23, 2017

hi if you are still interested. your code works awesome in iOS but it doesn't work on android. do you have any idea how to make it work on android.

@dead23angel
Copy link

@bispul hi!
I work on android

@umarrudi
Copy link

umarrudi commented Sep 7, 2018

Hi, can you explain more detail why this code work? I still confused how the if statement work, thnks

@hackrx
Copy link

hackrx commented May 25, 2020

You guys can check out this, this really worked great for me.
https://gist.github.com/mrzmyr/9ac94ca4622c1602a2a3
or example
https://snack.expo.io/@karniej/cGhvdG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment