fix: Improve drag threshold handling in useInertialHorizontalScroll hook
This commit is contained in:
@@ -236,11 +236,18 @@ export function useInertialHorizontalScroll(
|
|||||||
const deltaPrimary = currentPrimary - state.startPrimary;
|
const deltaPrimary = currentPrimary - state.startPrimary;
|
||||||
const now = evt.timeStamp;
|
const now = evt.timeStamp;
|
||||||
const deltaTime = Math.max(now - state.lastTime, 1);
|
const deltaTime = Math.max(now - state.lastTime, 1);
|
||||||
|
const hasExceededThreshold = Math.abs(deltaPrimary) >= resolvedOptions.dragThreshold;
|
||||||
|
|
||||||
if (Math.abs(deltaPrimary) >= resolvedOptions.dragThreshold) {
|
if (hasExceededThreshold) {
|
||||||
state.moved = true;
|
state.moved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!state.moved) {
|
||||||
|
state.lastPrimary = currentPrimary;
|
||||||
|
state.lastTime = now;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
evt.preventDefault?.();
|
evt.preventDefault?.();
|
||||||
|
|
||||||
if (isHorizontal) {
|
if (isHorizontal) {
|
||||||
@@ -272,8 +279,6 @@ export function useInertialHorizontalScroll(
|
|||||||
const isHorizontal = resolvedOptions.axis === 'x';
|
const isHorizontal = resolvedOptions.axis === 'x';
|
||||||
|
|
||||||
stopInertia();
|
stopInertia();
|
||||||
evt.preventDefault();
|
|
||||||
evt.stopPropagation();
|
|
||||||
|
|
||||||
state.activePointerId = evt.pointerId;
|
state.activePointerId = evt.pointerId;
|
||||||
state.startPrimary = isHorizontal ? evt.clientX : evt.clientY;
|
state.startPrimary = isHorizontal ? evt.clientX : evt.clientY;
|
||||||
|
|||||||
Reference in New Issue
Block a user