victor HF Staff commited on
Commit
bb5b6b1
·
1 Parent(s): 2d5923d

Prevent Safari back gesture in mobile nav

Browse files

Adds e.preventDefault() to block Safari's back navigation gesture on iOS when opening the mobile nav. Sets touchstart event listener to passive: false to allow preventDefault().

src/lib/components/MobileNav.svelte CHANGED
@@ -102,6 +102,8 @@
102
  // Exception: overlay tap (no scroll content, so no direction conflict)
103
  if (!isOpen && touch.clientX < 40) {
104
  // Opening gesture - wait for direction lock before starting drag
 
 
105
  potentialDrag = true;
106
  dragStartedOpen = false;
107
  } else if (isOpen && !touchOnDrawer) {
@@ -197,7 +199,8 @@
197
  }
198
 
199
  onMount(() => {
200
- window.addEventListener("touchstart", onTouchStart, { passive: true });
 
201
  window.addEventListener("touchmove", onTouchMove, { passive: true });
202
  window.addEventListener("touchend", onTouchEnd, { passive: true });
203
  window.addEventListener("touchcancel", onTouchCancel, { passive: true });
 
102
  // Exception: overlay tap (no scroll content, so no direction conflict)
103
  if (!isOpen && touch.clientX < 40) {
104
  // Opening gesture - wait for direction lock before starting drag
105
+ // Prevent Safari's back navigation gesture on iOS
106
+ e.preventDefault();
107
  potentialDrag = true;
108
  dragStartedOpen = false;
109
  } else if (isOpen && !touchOnDrawer) {
 
199
  }
200
 
201
  onMount(() => {
202
+ // touchstart needs passive: false to allow preventDefault() for Safari back gesture
203
+ window.addEventListener("touchstart", onTouchStart, { passive: false });
204
  window.addEventListener("touchmove", onTouchMove, { passive: true });
205
  window.addEventListener("touchend", onTouchEnd, { passive: true });
206
  window.addEventListener("touchcancel", onTouchCancel, { passive: true });