Skip to content

Commit

Permalink
fix: Safari drag issue (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Feb 3, 2024
1 parent 9856873 commit 0e0c772
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-dingos-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vaul-svelte": patch
---

fix bug preventing drawer from dragging on Safari
26 changes: 23 additions & 3 deletions src/lib/internal/vaul.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,30 @@ function getDistanceMoved(
direction: DrawerDirection,
event: SvelteEvent<PointerEvent | MouseEvent | TouchEvent, HTMLElement>
) {
const screenY = event instanceof TouchEvent ? event.changedTouches[0].screenY : event.screenY;
const screenX = event instanceof TouchEvent ? event.changedTouches[0].screenX : event.screenX;
if (event.type.startsWith("touch")) {
return getDistanceMovedForTouch(pointerStart, direction, event as TouchEvent);
} else {
return getDistanceMovedForPointer(pointerStart, direction, event as PointerEvent);
}
}

return pointerStart - (isVertical(direction) ? screenY : screenX);
function getDistanceMovedForPointer(
pointerStart: number,
direction: DrawerDirection,
event: PointerEvent | MouseEvent
) {
return pointerStart - (isVertical(direction) ? event.screenY : event.screenX);
}

function getDistanceMovedForTouch(
pointerStart: number,
direction: DrawerDirection,
event: TouchEvent
) {
return (
pointerStart -
(isVertical(direction) ? event.changedTouches[0].screenY : event.changedTouches[0].screenX)
);
}

function getDirectionMultiplier(direction: DrawerDirection) {
Expand Down

0 comments on commit 0e0c772

Please sign in to comment.