Skip to content

Commit

Permalink
fix: rely on screenY in stead of clientY for determining drag distance (
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejilderda authored Nov 6, 2023
1 parent 59937a5 commit 436d0a3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function Root({
// Ensure we maintain correct pointer capture even when going outside of the drawer
(event.target as HTMLElement).setPointerCapture(event.pointerId);

pointerStartY.current = event.clientY;
pointerStartY.current = event.screenY;
}

function shouldDrag(el: EventTarget, isDraggingDown: boolean) {
Expand Down Expand Up @@ -210,7 +210,7 @@ function Root({
function onDrag(event: React.PointerEvent<HTMLDivElement>) {
// We need to know how much of the drawer has been dragged in percentages so that we can transform background accordingly
if (isDragging) {
const draggedDistance = pointerStartY.current - event.clientY;
const draggedDistance = pointerStartY.current - event.screenY;
const isDraggingDown = draggedDistance > 0;

// Disallow dragging down to close when first snap point is the active one and dismissible prop is set to false.
Expand Down Expand Up @@ -469,7 +469,7 @@ function Root({

if (dragStartTime.current === null) return;

const y = event.clientY;
const y = event.screenY;

const timeTaken = dragEndTime.current.getTime() - dragStartTime.current.getTime();
const distMoved = pointerStartY.current - y;
Expand Down

0 comments on commit 436d0a3

Please sign in to comment.