diff --git a/app/hooks/useSwipe.tsx b/app/hooks/useSwipe.tsx index c95d5d6af9..5c2b5b089a 100644 --- a/app/hooks/useSwipe.tsx +++ b/app/hooks/useSwipe.tsx @@ -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();