-
-
Save leonidkuznetsov18/284f33603b4c811db8411f5cb7980a04 to your computer and use it in GitHub Desktop.
Double touch tap workaround for React based on onTouchTap (react-tap-event-plugin)
This file contains 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 dblTouchTapMaxDelay = 300 | |
let latestTouchTap = { | |
time: 0, | |
target: null, | |
} | |
export default function isDblTouchTap(event) { | |
const touchTap = { | |
time: new Date().getTime(), | |
target: event.currentTarget, | |
} | |
const isFastDblTouchTap = ( | |
touchTap.target === latestTouchTap.target && | |
touchTap.time - latestTouchTap.time < dblTouchTapMaxDelay | |
) | |
latestTouchTap = touchTap | |
return isFastDblTouchTap | |
} |
This file contains 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
// add onTouchTap support to avoid 300ms onClick delay on touchscreen (like iOS) | |
import injectTapEventPlugin from "react-tap-event-plugin" | |
injectTapEventPlugin() | |
import isDblTouchTap from "./isDblTouchTap" | |
// ... | |
<div | |
onTouchTap={ (e) => { | |
if (isDblTouchTap(e)) { | |
// == onDblTouchTap | |
} | |
} } | |
> | |
... | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment