fix: Ignore small movements on useSwipe hook (#13549)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-08-24 16:59:50 -04:00
1 parent 83dfea1953
commit 237c3c2e2d
1 file changed
+9
+9
View File
@@ -1,6 +1,9 @@
import { isNumber } from "es-toolkit/compat";
import { useRef } from "react";
/** Minimum distance in pixels that a touch must travel to count as a swipe. */
const MinSwipeDistance = 40;
type Props = {
onSwipeRight: () => void;
onSwipeLeft: () => void;
@@ -47,6 +50,12 @@ export default function useSwipe({
const dx = touchXEnd.current - touchXStart.current;
const dy = touchYEnd.current - touchYStart.current;
// Ignore small movements so that a tap, or the start of a gesture, is not
// mistaken for a swipe.
if (Math.max(Math.abs(dx), Math.abs(dy)) < MinSwipeDistance) {
return;
}
const swipeRight = dx > 0 && Math.abs(dy) < Math.abs(dx);
if (swipeRight) {
resetTouchPoints();