mirror of
https://github.com/outline/outline.git
synced 2026-11-28 00:09:58 +03:00
fix: Ignore small movements on useSwipe hook (#13549)
This commit is contained in:
1 parent
83dfea1953
commit
237c3c2e2d
1 file changed
+9
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user