diff --git a/client/src/components/Journey/PhotoLightbox.test.tsx b/client/src/components/Journey/PhotoLightbox.test.tsx
index 9cd898883..1675afa97 100644
--- a/client/src/components/Journey/PhotoLightbox.test.tsx
+++ b/client/src/components/Journey/PhotoLightbox.test.tsx
@@ -87,9 +87,9 @@ describe('PhotoLightbox', () => {
it('FE-COMP-LIGHTBOX-007: does not render when photos array is empty', () => {
const onClose = vi.fn();
- const { container } = render( );
+ render( );
// Component returns null when photo is undefined (empty array, index 0 is undefined)
- expect(container.querySelector('img')).not.toBeInTheDocument();
+ expect(document.querySelector('img')).not.toBeInTheDocument();
});
it('FE-COMP-LIGHTBOX-008: calls onClose when close button clicked', () => {
@@ -100,10 +100,10 @@ describe('PhotoLightbox', () => {
});
it('FE-COMP-LIGHTBOX-009: opens at the requested start index', () => {
- const { container } = render( );
+ render( );
expect(screen.getByText('3 / 3')).toBeInTheDocument();
// The third photo has no caption, so its img is presentational.
- expect(container.querySelector('img')).toHaveAttribute('src', '/photos/3.jpg');
+ expect(document.querySelector('img')).toHaveAttribute('src', '/photos/3.jpg');
});
it('FE-COMP-LIGHTBOX-010: only offers the arrows that lead somewhere', () => {
@@ -162,8 +162,8 @@ describe('PhotoLightbox', () => {
});
it('FE-COMP-LIGHTBOX-015: swipes horizontally to move between photos', () => {
- const { container } = render( );
- const surface = container.firstElementChild as HTMLElement;
+ render( );
+ const surface = screen.getByRole('dialog');
fireEvent.touchStart(surface, { touches: [{ clientX: 200, clientY: 200 }] });
fireEvent.touchEnd(surface, { changedTouches: [{ clientX: 100, clientY: 210 }] });
@@ -176,8 +176,8 @@ describe('PhotoLightbox', () => {
it('FE-COMP-LIGHTBOX-016: swipes down to close', () => {
const onClose = vi.fn();
- const { container } = render( );
- const surface = container.firstElementChild as HTMLElement;
+ render( );
+ const surface = screen.getByRole('dialog');
fireEvent.touchStart(surface, { touches: [{ clientX: 200, clientY: 100 }] });
fireEvent.touchEnd(surface, { changedTouches: [{ clientX: 210, clientY: 300 }] });
@@ -187,8 +187,8 @@ describe('PhotoLightbox', () => {
it('FE-COMP-LIGHTBOX-017: ignores a touch end without a matching touch start', () => {
const onClose = vi.fn();
- const { container } = render( );
- const surface = container.firstElementChild as HTMLElement;
+ render( );
+ const surface = screen.getByRole('dialog');
fireEvent.touchEnd(surface, { changedTouches: [{ clientX: 210, clientY: 300 }] });
@@ -294,8 +294,8 @@ describe('PhotoLightbox', () => {
});
it('FE-COMP-LIGHTBOX-026: a swipe to the right turns to the next photo', () => {
- const { container } = render( );
- const surface = container.firstElementChild as HTMLElement;
+ render( );
+ const surface = screen.getByRole('dialog');
fireEvent.touchStart(surface, { touches: [{ clientX: 100, clientY: 200 }] });
fireEvent.touchEnd(surface, { changedTouches: [{ clientX: 200, clientY: 210 }] });
diff --git a/client/src/components/Journey/PhotoLightbox.tsx b/client/src/components/Journey/PhotoLightbox.tsx
index 0c890afec..3fc05269d 100644
--- a/client/src/components/Journey/PhotoLightbox.tsx
+++ b/client/src/components/Journey/PhotoLightbox.tsx
@@ -1,9 +1,11 @@
import { useState, useEffect, useCallback, useRef } from 'react'
+import { createPortal } from 'react-dom'
import { ChevronLeft, ChevronRight, Loader2, X, ZoomIn, ZoomOut } from 'lucide-react'
import VideoPlayer from './VideoPlayerLazy'
import { usePhotoZoom } from './usePhotoZoom'
import { Tooltip } from '../shared/Tooltip'
import { isRtlLanguage, useTranslation } from '../../i18n'
+import { lockBodyScroll } from '../../utils/bodyScrollLock'
interface LightboxPhoto {
id: string
@@ -34,10 +36,22 @@ interface Props {
/** The round glass buttons of the top bar. */
const ROUND_BTN: React.CSSProperties = {
background: 'rgba(255,255,255,0.1)', border: 'none', borderRadius: '50%',
- width: 36, height: 36, display: 'flex', alignItems: 'center', justifyContent: 'center',
- color: '#fff', cursor: 'pointer',
+ width: 40, height: 40, display: 'flex', alignItems: 'center', justifyContent: 'center',
+ color: '#fff', cursor: 'pointer', flex: 'none',
}
+/** Close is the one every visitor needs: a little stronger than the rest. */
+const CLOSE_BTN: React.CSSProperties = { ...ROUND_BTN, background: 'rgba(255,255,255,0.18)' }
+
+/**
+ * The device's insets, from whichever source reports them: env() in a browser,
+ * the values Capacitor's SystemBars writes on Android, the ones the iOS app
+ * measures itself. The viewer is portalled to
, outside the phone shell
+ * that defines its own --m-safe-* tokens, so it reads the sources directly.
+ */
+const SAFE = (side: 'top' | 'bottom' | 'left' | 'right') =>
+ `max(env(safe-area-inset-${side}, 0px), var(--safe-area-inset-${side}, 0px), var(--trek-native-safe-${side}, 0px))`
+
export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }: Props) {
const [idx, setIdx] = useState(startIndex)
const touchStart = useRef<{ x: number; y: number } | null>(null)
@@ -51,7 +65,11 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
useEffect(() => {
const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null
dialogRef.current?.focus()
- return () => opener?.focus()
+ const unlock = lockBodyScroll()
+ return () => {
+ unlock()
+ opener?.focus()
+ }
}, [])
const photo = photos[idx]
@@ -111,7 +129,9 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
if (!photo) return null
- return (
+ // Portalled to : inside a transformed sheet or pane, `fixed` would be
+ // relative to that box and the viewer would open as a small window in it.
+ return createPortal(
- {/* Photo area — centered with nav overlays */}
-
- {/* Top bar */}
-
-
- {idx + 1} / {photos.length}
-
-
+ {/* Top bar: its own row below the status bar and a notch, so the close
+ button is always there to tap and never sits over the photo. */}
+
+
+ {idx + 1} / {photos.length}
+
+
{isImage && (
<>
@@ -162,16 +183,17 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
>
)}
-
-
+
+
-
+
+ {/* Photo area: what is left below the bar, with the page arrows over it. */}
+
{/* Prev button — visible on hover (desktop), always visible (mobile) */}
{hasPrev && (
setLoadedId(photo.id)}
{...zoom.mouse}
style={{
- maxWidth: '92vw', maxHeight: '92vh',
+ maxWidth: '100%', maxHeight: '100%',
objectFit: 'contain', borderRadius: 4,
animation: 'fadeIn 0.15s ease',
userSelect: 'none',
@@ -212,7 +234,7 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
{loading && (
{photo.thumbSrc && (
-
+
)}
@@ -252,6 +274,7 @@ export default function PhotoLightbox({ photos, startIndex = 0, onClose, label }
)}
-
+
,
+ document.body,
)
}
diff --git a/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx b/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx
index 21cc34156..c8b501017 100644
--- a/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx
+++ b/client/src/mobile/screens/trip/tabs/MFileLightbox.tsx
@@ -45,13 +45,19 @@ export default function MFileLightbox({ files, index, onIndexChange, onClose, t
// tap-to-dismiss. Escape / arrow keys and the header buttons are the
// keyboard equivalents, wired up in useMediaLightbox.
role="presentation"
- className="m-root fixed inset-0 z-[65] flex flex-col bg-black/[.92]"
+ className="m-root fixed inset-0 z-[65] flex flex-col bg-black/[.92] pb-[env(safe-area-inset-bottom,0px)]"
onClick={onClose}
onTouchStart={onTouchStart}
onTouchEnd={onTouchEnd}
>
{/* Header */}
-
e.stopPropagation()}>
+ {/* Below the status bar and a notch, and clear of a side inset in landscape,
+ so the close button is always there to tap. */}
+
e.stopPropagation()}
+ >
{file.original_name}
{index + 1} / {files.length}
@@ -73,8 +79,13 @@ export default function MFileLightbox({ files, index, onIndexChange, onClose, t
>
-
-
+
+