Skip to content

Instantly share code, notes, and snippets.

@leonidkuznetsov18
Forked from MoOx/isDblTouchTap.js
Created January 31, 2018 09:18
Show Gist options
  • Save leonidkuznetsov18/284f33603b4c811db8411f5cb7980a04 to your computer and use it in GitHub Desktop.
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)
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
}
// 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