Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: prevent iOS pinch zoom from changing media previews

[._.]/ Adam Eivy42345c313469
diff --git a/client/src/components/media/MediaLightbox.jsx b/client/src/components/media/MediaLightbox.jsx
index 1d6ca2c5c7..5e8af7fbc2 100644
--- a/client/src/components/media/MediaLightbox.jsx
+++ b/client/src/components/media/MediaLightbox.jsx
@@ -202,7 +202,7 @@ export default function MediaLightbox({
// Reset refine modal when the previewed item changes.
useEffect(() => { setRefineOpen(false); setPromptFromOpen(false); }, [item?.key]);
- const { onTouchStart, onTouchEnd } = useSwipeNav({ onPrevious, onNext, hasPrevious, hasNext });
+ const { onTouchStart, onTouchEnd, onTouchCancel } = useSwipeNav({ onPrevious, onNext, hasPrevious, hasNext });
if (!item) return null;
const isVideo = item.kind === 'video';
@@ -355,6 +355,12 @@ export default function MediaLightbox({
className="flex-1 bg-black flex items-center justify-center min-h-0 relative"
onTouchStart={onTouchStart}
onTouchEnd={onTouchEnd}
+ onTouchCancel={onTouchCancel}
+ // Keep native pinch/pan available for inspecting an image. The
+ // swipe hook explicitly opts out once a second finger or a zoomed
+ // visual viewport appears, so native zoom cannot turn into gallery
+ // navigation while the browser is handling the gesture.
+ style={{ touchAction: 'manipulation' }}
>
{isVideo ? (
/* Mobile playback contract:
diff --git a/client/src/components/media/MediaLightbox.test.jsx b/client/src/components/media/MediaLightbox.test.jsx
index 4bda49664f..c28b7b9ca3 100644
--- a/client/src/components/media/MediaLightbox.test.jsx
+++ b/client/src/components/media/MediaLightbox.test.jsx
@@ -119,6 +119,59 @@ describe('MediaLightbox overlay portal', () => {
});
});
+describe('MediaLightbox touch gestures', () => {
+ it('keeps native pinch input from navigating the gallery', () => {
+ const onPrevious = vi.fn();
+ const onNext = vi.fn();
+ render(
+ <MediaLightbox
+ item={imageItem}
+ onClose={() => {}}
+ onPrevious={onPrevious}
+ onNext={onNext}
+ hasPrevious
+ hasNext
+ />
+ );
+
+ const surface = screen.getByRole('img').parentElement;
+ expect(surface.style.touchAction).toBe('manipulation');
+
+ fireEvent.touchStart(surface, { touches: [{ clientX: 300, clientY: 400 }] });
+ fireEvent.touchStart(surface, {
+ touches: [
+ { clientX: 300, clientY: 400 },
+ { clientX: 500, clientY: 400 },
+ ],
+ });
+ fireEvent.touchEnd(surface, {
+ touches: [{ clientX: 300, clientY: 400 }],
+ changedTouches: [{ clientX: 80, clientY: 400 }],
+ });
+ fireEvent.touchEnd(surface, {
+ touches: [],
+ changedTouches: [{ clientX: 80, clientY: 400 }],
+ });
+
+ expect(onPrevious).not.toHaveBeenCalled();
+ expect(onNext).not.toHaveBeenCalled();
+ });
+
+ it('keeps one-finger horizontal swipes for gallery navigation', () => {
+ const onNext = vi.fn();
+ render(<MediaLightbox item={imageItem} onClose={() => {}} onNext={onNext} hasNext />);
+
+ const surface = screen.getByRole('img').parentElement;
+ fireEvent.touchStart(surface, { touches: [{ clientX: 300, clientY: 400 }] });
+ fireEvent.touchEnd(surface, {
+ touches: [],
+ changedTouches: [{ clientX: 80, clientY: 400 }],
+ });
+
+ expect(onNext).toHaveBeenCalledTimes(1);
+ });
+});
+
describe('MediaLightbox Escape cascade', () => {
it('exits full screen without closing the lightbox', () => {
const onClose = vi.fn();
diff --git a/client/src/hooks/useSwipeNav.js b/client/src/hooks/useSwipeNav.js
index 44ccc6d798..6259c46b8d 100644
--- a/client/src/hooks/useSwipeNav.js
+++ b/client/src/hooks/useSwipeNav.js
@@ -4,6 +4,7 @@ import { useRef, useCallback } from 'react';
// diagonal scrolls from registering as nav but stays forgiving for thumb swipes.
const SWIPE_MIN_PX = 50;
const HORIZONTAL_BIAS = 1.2;
+const EMPTY_TOUCH_START = { x: null, y: null };
// Ignore touches that *originate* on an inline button so a tap on the
// surface (e.g. the fullscreen toggle) isn't seeded as a swipe-start. The
@@ -17,27 +18,50 @@ const HORIZONTAL_BIAS = 1.2;
// Optional-chain on `closest` because touch targets aren't guaranteed to
// be Elements (e.g. Text nodes, jsdom-style envs).
const isButtonTouch = (e) => !!e.target?.closest?.('button');
+const isViewportZoomed = () => {
+ const scale = globalThis.visualViewport?.scale;
+ return typeof scale === 'number' && scale > 1;
+};
export function useSwipeNav({ onPrevious, onNext, hasPrevious = false, hasNext = false } = {}) {
- const touchStart = useRef({ x: null, y: null });
+ const touchStart = useRef(EMPTY_TOUCH_START);
+
+ const resetTouchStart = useCallback(() => {
+ touchStart.current = EMPTY_TOUCH_START;
+ }, []);
const onTouchStart = useCallback((e) => {
- if (isButtonTouch(e)) { touchStart.current = { x: null, y: null }; return; }
+ // A second finger must cancel the one-finger gesture. Otherwise iOS can
+ // report the end of a pinch as a long horizontal swipe and change the
+ // preview while the user is zooming it.
+ if (e.touches?.length !== 1 || isButtonTouch(e) || isViewportZoomed()) {
+ touchStart.current = EMPTY_TOUCH_START;
+ return;
+ }
const t = e.touches[0];
+ if (!t) { touchStart.current = EMPTY_TOUCH_START; return; }
touchStart.current = { x: t.clientX, y: t.clientY };
}, []);
const onTouchEnd = useCallback((e) => {
const start = touchStart.current;
if (start.x == null) return;
+ // Ignore the first finger leaving a multi-touch gesture, and any pan
+ // after the browser has zoomed the visual viewport. The latter is how a
+ // user inspects the enlarged image without accidentally navigating away.
+ if ((e.touches?.length || 0) > 0 || isViewportZoomed()) {
+ touchStart.current = EMPTY_TOUCH_START;
+ return;
+ }
const end = e.changedTouches[0];
+ if (!end) { touchStart.current = EMPTY_TOUCH_START; return; }
const dx = end.clientX - start.x;
const dy = end.clientY - start.y;
- touchStart.current = { x: null, y: null };
+ touchStart.current = EMPTY_TOUCH_START;
if (Math.abs(dx) < SWIPE_MIN_PX || Math.abs(dx) <= Math.abs(dy) * HORIZONTAL_BIAS) return;
if (dx > 0 && hasPrevious) onPrevious?.();
else if (dx < 0 && hasNext) onNext?.();
}, [hasPrevious, hasNext, onPrevious, onNext]);
- return { onTouchStart, onTouchEnd };
+ return { onTouchStart, onTouchEnd, onTouchCancel: resetTouchStart };
}