Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rely on screenY in stead of clientY for determining drag distance #154

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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 @@ -205,7 +205,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 @@ -464,7 +464,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