Skip to content

Commit

Permalink
Merge pull request #843 from brunosabot/fix/hold-is-triggering-when-s…
Browse files Browse the repository at this point in the history
…crolling

fix: do not fire hold if a scroll is made
  • Loading branch information
Clooos authored Oct 12, 2024
2 parents 719daa5 + 72f8679 commit 2707d9e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tools/tap-actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tapFeedback, forwardHaptic } from "./utils.ts";

const maxHoldDuration = 200;
const maxHoldDuration = 500;
const doubleTapTimeout = 200;

// Global event listener
Expand Down Expand Up @@ -30,6 +30,7 @@ document.body.addEventListener('pointerdown', (event) => {
actionElement.actionHandler.handleStart(event);

actionElement.addEventListener('pointerup', actionElement.actionHandler.handleEnd.bind(actionElement.actionHandler), { once: true });
document.addEventListener('scroll', actionElement.actionHandler.handleScroll.bind(actionElement.actionHandler), { once: true });
}
});

Expand Down Expand Up @@ -154,6 +155,12 @@ class ActionHandler {
this.lastTap = currentTime;
this.startTime = null; // Reset start time
}

handleScroll() {
// Reset hold timeout if it's not triggered yet
clearTimeout(this.holdTimeout);
this.holdTimeout = null; // Reset hold timeout
}
}

// sendActionEvent function
Expand Down

0 comments on commit 2707d9e

Please sign in to comment.