mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
fix(native): one size class the keyboard cannot move, shortcuts that wait for sheets
From the large-screen review (code findings H1, M1, M2, M3, M4, M7, L1, L3, L4, L6, L7): - The size class is one value in JavaScript (hooks/sizeClass.ts) and the stylesheet follows it: MobileShell writes it to the shell as data-size, the wide:/split: variants and mobile.css key on that instead of media queries of their own. A window that only grows shorter at the same width while a field has focus is Android's soft keyboard, not a new window, so the rail, the form sheets and the panes no longer fold away (and take the focused field with them) while one types. - The large-screen layout is the app's only. In a browser the touch shell is the phone's below 768px and stays compact there, as before this branch. - Shortcuts are the app's only, so a browser keeps Ctrl+1 and Alt+Left. The command key is the platform's own (Cmd on Apple, Ctrl elsewhere), digits are matched by the key's place as well (AZERTY), and nothing runs while a sheet or another modal dialog is open: the page listens to nothing and the app is handed no key commands, so Cmd+[ can no longer drop an unsaved form. - Inside a trip Cmd+N belongs to the trip shell and creates what the tab on show creates, named after it. - Inside the touch shell the desktop navbar of the few PageShell routes is hidden and --nav-h is 0. - The rail comes before the page in the DOM, so a keyboard reaches it first. - The phone's deep day colour for a journey card without a photo stays the phone's; the desktop and shared timelines keep their faint wash. Its card is opaque, a suggestion included, so the map's names do not read through. - The trip widget's iPad mini layout keys on the iPad mini's width alone. - The trip dock gets the scroll-edge strip and the denser dock glass the global dock has. - Duplicate test id FE-MOB-PANES-016 renumbered.
This commit is contained in:
@@ -4,7 +4,7 @@ import BottomNav from '../components/Layout/BottomNav'
|
||||
import ErrorBoundary from '../components/shared/ErrorBoundary'
|
||||
import MBottomNav from './components/MBottomNav'
|
||||
import MNavRail from './components/MNavRail'
|
||||
import { useIsWide } from '../hooks/sizeClass'
|
||||
import { useSizeClass } from '../hooks/sizeClass'
|
||||
import MKeyboardHost from './keyboard/MKeyboardHost'
|
||||
import MShellShortcuts from './keyboard/MShellShortcuts'
|
||||
import MToastHost from './components/MToastHost'
|
||||
@@ -45,8 +45,10 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) {
|
||||
const pageRef = useRef<HTMLDivElement>(null)
|
||||
const edgeBack = isNativeIos() && caps.features.includes('edgeBack')
|
||||
// On a wide window (an iPad, a foldable unfolded) the rail on the leading edge
|
||||
// replaces the dock, and the page column starts after it.
|
||||
const wide = useIsWide()
|
||||
// replaces the dock, and the page column starts after it. The class goes on the
|
||||
// root as data-size: the wide:/split: variants and mobile.css key on it.
|
||||
const sizeClass = useSizeClass()
|
||||
const wide = sizeClass !== 'compact'
|
||||
// A foldable's fold, as the Android app reports it: two-pane screens end their
|
||||
// leading pane there (mobile.css, data-fold).
|
||||
const fold = useWindowFold()
|
||||
@@ -66,7 +68,7 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) {
|
||||
return (
|
||||
// min-h-svh, not min-h-dvh: dvh grows while Safari's toolbar retracts, so a
|
||||
// dvh page length would chase the animation it just triggered.
|
||||
<div className="m-root m-shell flex min-h-svh flex-col text-m-ink" data-fold={fold ? 'vertical' : undefined} style={foldStyle}>
|
||||
<div className="m-root m-shell flex min-h-svh flex-col text-m-ink" data-size={sizeClass} data-fold={fold ? 'vertical' : undefined} style={foldStyle}>
|
||||
{/* Background and screen gradient live on their own viewport-sized layer.
|
||||
The shell root is as tall as the document now, and --m-scr is a radial
|
||||
gradient measured against its element box, so on it the light cone would
|
||||
@@ -80,10 +82,16 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) {
|
||||
layer to be visible, body must not paint over it, which index.css handles
|
||||
for this breakpoint. */}
|
||||
<div aria-hidden className="pointer-events-none fixed inset-0 -z-10 bg-[color:var(--m-bg)] bg-[image:var(--m-scr)]" />
|
||||
{/* The rail comes before the page in the document, as it does on screen,
|
||||
so a keyboard (Full Keyboard Access on an iPad) reaches the navigation
|
||||
first. It is fixed, so where it sits in the DOM moves nothing. */}
|
||||
{!inTripPlanner && wide && (
|
||||
<ErrorBoundary boundaryId="chrome:m-nav-rail" fallback={null}><MNavRail /></ErrorBoundary>
|
||||
)}
|
||||
<div ref={pageRef} className="flex-1 wide:ps-[var(--m-rail-w)]">{children}</div>
|
||||
<MEdgeBack target={pageRef} enabled={edgeBack} />
|
||||
{!inTripPlanner && (
|
||||
<ErrorBoundary boundaryId="chrome:m-bottom-nav" fallback={null}>{wide ? <MNavRail /> : <MBottomNav />}</ErrorBoundary>
|
||||
{!inTripPlanner && !wide && (
|
||||
<ErrorBoundary boundaryId="chrome:m-bottom-nav" fallback={null}><MBottomNav /></ErrorBoundary>
|
||||
)}
|
||||
<ErrorBoundary boundaryId="chrome:m-toast" fallback={null}><MToastHost /></ErrorBoundary>
|
||||
{/* A hardware keyboard (an iPad's, mostly) gets the shortcuts an iPad app has. */}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* The screen's own background under a floating dock, fading out upwards. The
|
||||
* dock floats 12px above the screen's foot, and in that gap scrolled content
|
||||
* used to stay sharp: a pill, a name and an avatar peeking out under the bar.
|
||||
* Now the page ends where the dock begins, the way an iOS bar's scroll edge
|
||||
* does.
|
||||
*
|
||||
* The same layer as the shell's background (MobileShell), the colour and the
|
||||
* screen gradient over the whole window, masked down to the strip at the foot,
|
||||
* so the strip is exactly the colour behind it and shows no band. Above the
|
||||
* dock's middle the mask is clear, so nothing that sits above the dock (a stats
|
||||
* card, a carousel) is touched.
|
||||
*/
|
||||
export default function MDockScrim() {
|
||||
return (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="m-dock-scrim pointer-events-none fixed inset-0 z-[39] bg-[color:var(--m-bg)] bg-[image:var(--m-scr)]"
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,49 +1,76 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useNativeCapabilities } from '../../native/capabilities';
|
||||
import { isNativeApp, isNativeIos } from '../../native/platform';
|
||||
import { reportNativeFailure } from '../../native/reportFailure';
|
||||
import { TrekShell } from '../../native/trekShell';
|
||||
import { hasOpenOverlay, useHasOpenOverlay } from '../overlayStack';
|
||||
import { findShortcut, toNativeCommand, useShortcutRegistry } from './shortcuts';
|
||||
|
||||
/**
|
||||
* Whether a modal is in front of the page: a sheet (it registers on the overlay
|
||||
* stack) or any other dialog that marks itself aria-modal. The page's shortcuts
|
||||
* wait behind it. ⌘[ while a reservation was being edited used to leave the trip
|
||||
* and drop the form without the "discard changes?" a tap on the scrim asks.
|
||||
*/
|
||||
function modalOpen(): boolean {
|
||||
if (hasOpenOverlay()) return true;
|
||||
// A dialog kept mounted while closed (the assistant's) is hidden, not gone.
|
||||
return Array.from(document.querySelectorAll('[aria-modal="true"]')).some((el) => !el.closest('[hidden]'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers the touch shell's keyboard shortcuts (useShortcuts), once for every
|
||||
* screen. In a browser it listens for the keys itself. In the app the binary
|
||||
* takes them over as native key commands when it can (feature keyCommands):
|
||||
* on iOS they show in the overlay a held ⌘ shows and in the iPadOS menu bar,
|
||||
* on Android in the system's keyboard shortcuts list. The page then leaves
|
||||
* those keys alone, so nothing runs twice. Only a shell that has the feature
|
||||
* reports it, so the feature alone decides, whatever the platform.
|
||||
* screen, in the app only. A browser keeps its own keys: there the touch shell
|
||||
* is a phone layout, and Ctrl+1 is a tab switch and Alt+← is Back.
|
||||
*
|
||||
* The binary takes the shortcuts over as native key commands when it can
|
||||
* (feature keyCommands): on iOS they show in the overlay a held ⌘ shows and in
|
||||
* the iPadOS menu bar, on Android in the system's keyboard shortcuts list. The
|
||||
* page then leaves those keys alone, so nothing runs twice. Only a shell that
|
||||
* has the feature reports it, so the feature alone decides, whatever the
|
||||
* platform. An older binary without it leaves every key to the page.
|
||||
*
|
||||
* While a sheet or dialog is open none of them run: the page listens to
|
||||
* nothing and the app's list is emptied, so a shortcut can neither navigate
|
||||
* away under an unsaved form nor open a second editor over it.
|
||||
*/
|
||||
export default function MKeyboardHost() {
|
||||
const lists = useShortcutRegistry((s) => s.lists);
|
||||
const { caps } = useNativeCapabilities();
|
||||
const native = caps.features.includes('keyCommands');
|
||||
const app = isNativeApp();
|
||||
const native = app && caps.features.includes('keyCommands');
|
||||
const blocked = useHasOpenOverlay();
|
||||
|
||||
useEffect(() => {
|
||||
if (!app) return;
|
||||
const apple = isNativeIos();
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.defaultPrevented || e.isComposing) return;
|
||||
if (e.defaultPrevented || e.isComposing || modalOpen()) return;
|
||||
const all = lists.map((l) => l.shortcuts);
|
||||
const hit = findShortcut(e, native ? all.map((l) => l.filter((s) => !s.mod && !s.ctrl)) : all);
|
||||
const hit = findShortcut(e, native ? all.map((l) => l.filter((s) => !s.mod && !s.ctrl)) : all, apple);
|
||||
if (!hit) return;
|
||||
e.preventDefault();
|
||||
hit.run();
|
||||
};
|
||||
document.addEventListener('keydown', onKey);
|
||||
return () => document.removeEventListener('keydown', onKey);
|
||||
}, [lists, native]);
|
||||
}, [lists, native, app]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!native) return;
|
||||
const commands = lists.flatMap((l) =>
|
||||
l.shortcuts.filter((s) => s.mod || s.ctrl).map((s) => toNativeCommand(l.owner, s))
|
||||
);
|
||||
const commands = blocked
|
||||
? []
|
||||
: lists.flatMap((l) => l.shortcuts.filter((s) => s.mod || s.ctrl).map((s) => toNativeCommand(l.owner, s)));
|
||||
TrekShell.setKeyCommands({ commands }).catch(reportNativeFailure);
|
||||
}, [lists, native]);
|
||||
}, [lists, native, blocked]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!native) return;
|
||||
let cancelled = false;
|
||||
let remove: (() => Promise<void>) | null = null;
|
||||
TrekShell.addListener('keyCommand', ({ id }) => {
|
||||
// A command can still arrive from a list sent before a dialog opened.
|
||||
if (modalOpen()) return;
|
||||
const at = id.indexOf(':');
|
||||
const owner = id.slice(0, at);
|
||||
const list = useShortcutRegistry.getState().lists.find((l) => l.owner === owner);
|
||||
|
||||
@@ -8,8 +8,9 @@ import { useShortcuts } from './useShortcuts';
|
||||
/**
|
||||
* The app-wide shortcuts of the touch shell: ⌘1 to ⌘9 for the sections in the
|
||||
* order the rail shows them, ⌘N for what the "+" creates here, ⌘, for
|
||||
* settings. Inside a trip the numbers belong to the trip's own sections
|
||||
* (MTripShell), so the shell lets go of them there.
|
||||
* settings. Inside a trip the numbers and ⌘N belong to the trip (MTripShell):
|
||||
* its tabs change without a new URL, and this component renders only on one,
|
||||
* so a ⌘N of its own would still create what the tab the trip opened on does.
|
||||
*/
|
||||
export default function MShellShortcuts() {
|
||||
const { t } = useTranslation();
|
||||
@@ -30,7 +31,7 @@ export default function MShellShortcuts() {
|
||||
mod: true,
|
||||
run: () => void navigate(item.to),
|
||||
}))),
|
||||
...(noCreate ? [] : [{ id: 'create', title: create.label, key: 'n', mod: true, run: create.run }]),
|
||||
...(noCreate || inTrip ? [] : [{ id: 'create', title: create.label, key: 'n', mod: true, run: create.run }]),
|
||||
{ id: 'settings', title: t('nav.bottomSettings'), key: ',', mod: true, run: () => void navigate('/settings') },
|
||||
];
|
||||
useShortcuts('shell', shortcuts);
|
||||
|
||||
@@ -11,9 +11,13 @@ export interface Shortcut {
|
||||
id: string;
|
||||
/** Its name, for the overlay a held ⌘ shows and the iPadOS menu bar. */
|
||||
title: string;
|
||||
/** KeyboardEvent.key, lower case for letters ('n', '1', ',', 'ArrowLeft'). */
|
||||
/**
|
||||
* KeyboardEvent.key, lower case for letters ('n', '1', ',', 'ArrowLeft'). A
|
||||
* digit is matched by the key's place as well (KeyboardEvent.code), since a
|
||||
* French keyboard types '&' on the 1 key without Shift.
|
||||
*/
|
||||
key: string;
|
||||
/** ⌘ on Apple keyboards, Ctrl elsewhere. */
|
||||
/** ⌘ on an iPad (and any Apple keyboard), Ctrl on Android. */
|
||||
mod?: boolean;
|
||||
shift?: boolean;
|
||||
alt?: boolean;
|
||||
@@ -22,17 +26,24 @@ export interface Shortcut {
|
||||
run: () => void;
|
||||
}
|
||||
|
||||
/** Whether an event is this shortcut. ⌘ and Ctrl both count as the command key. */
|
||||
export function matchesShortcut(
|
||||
e: Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey' | 'shiftKey' | 'altKey'>,
|
||||
s: Shortcut
|
||||
): boolean {
|
||||
type KeyEventLike = Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey' | 'shiftKey' | 'altKey'> &
|
||||
Partial<Pick<KeyboardEvent, 'code'>>;
|
||||
|
||||
/**
|
||||
* Whether an event is this shortcut. The command key is the platform's own: ⌘
|
||||
* on Apple keyboards, Ctrl elsewhere, never either one. Taking both made Ctrl+N
|
||||
* in a Mac text field (the "next line" binding) run ⌘N.
|
||||
*/
|
||||
export function matchesShortcut(e: KeyEventLike, s: Shortcut, apple = true): boolean {
|
||||
const key = e.key.length === 1 ? e.key.toLowerCase() : e.key;
|
||||
if (key !== s.key) return false;
|
||||
const digitAt = /^[0-9]$/.test(s.key) && e.code === `Digit${s.key}`;
|
||||
if (key !== s.key && !digitAt) return false;
|
||||
if (s.ctrl) {
|
||||
if (!e.ctrlKey || !e.metaKey) return false;
|
||||
} else if (!!s.mod !== (e.metaKey || e.ctrlKey)) {
|
||||
return false;
|
||||
} else {
|
||||
const command = apple ? e.metaKey : e.ctrlKey;
|
||||
const other = apple ? e.ctrlKey : e.metaKey;
|
||||
if (!!s.mod !== command || other) return false;
|
||||
}
|
||||
return !!s.shift === e.shiftKey && !!s.alt === e.altKey;
|
||||
}
|
||||
@@ -47,13 +58,14 @@ export function isTypingTarget(target: EventTarget | null): boolean {
|
||||
|
||||
/** The first shortcut of the lists (later ones first) that the event is. */
|
||||
export function findShortcut(
|
||||
e: Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey' | 'shiftKey' | 'altKey' | 'target'>,
|
||||
lists: Shortcut[][]
|
||||
e: KeyEventLike & Pick<KeyboardEvent, 'target'>,
|
||||
lists: Shortcut[][],
|
||||
apple = true
|
||||
): Shortcut | null {
|
||||
for (let i = lists.length - 1; i >= 0; i--) {
|
||||
for (const s of lists[i]) {
|
||||
if (!s.mod && !s.ctrl && isTypingTarget(e.target)) continue;
|
||||
if (matchesShortcut(e, s)) return s;
|
||||
if (matchesShortcut(e, s, apple)) return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
--m-bg: #F3F2EF;
|
||||
--m-scr: radial-gradient(120% 80% at 50% -10%, #FBFAF7 0%, #F1EFEA 55%, #E9E7E1 100%);
|
||||
--m-glass: rgba(255,255,255,.6);
|
||||
/* The dock's glass: denser than --m-glass, so a photo scrolling under it
|
||||
* neither turns it muddy nor washes out its icons. */
|
||||
--m-dock: rgba(255,255,255,.8);
|
||||
--m-gbr: rgba(255,255,255,.75);
|
||||
--m-card: rgba(255,255,255,.55);
|
||||
--m-cbr: rgba(255,255,255,.75);
|
||||
@@ -58,17 +61,17 @@
|
||||
--m-rail-w: 0px;
|
||||
}
|
||||
|
||||
/* Wide size class (hooks/sizeClass.ts WIDE_QUERY): the rail on the leading
|
||||
* edge takes the dock's place, so nothing docks at the bottom any more and
|
||||
* content only clears the home indicator. */
|
||||
@media (min-width: 600px) and (min-height: 501px) {
|
||||
.m-root {
|
||||
--bottom-nav-h: env(safe-area-inset-bottom, 0px);
|
||||
--m-rail-w: calc(env(safe-area-inset-left, 0px) + 92px);
|
||||
}
|
||||
:root[dir='rtl'] .m-root {
|
||||
--m-rail-w: calc(env(safe-area-inset-right, 0px) + 92px);
|
||||
}
|
||||
/* Wide size class (hooks/sizeClass.ts, written to the shell's root as
|
||||
* data-size): the rail on the leading edge takes the dock's place, so nothing
|
||||
* docks at the bottom any more and content only clears the home indicator.
|
||||
* Asked from <html>, so a sheet's own .m-root (portalled, perhaps to body)
|
||||
* reads the same values as the shell. */
|
||||
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-root {
|
||||
--bottom-nav-h: env(safe-area-inset-bottom, 0px);
|
||||
--m-rail-w: calc(env(safe-area-inset-left, 0px) + 100px);
|
||||
}
|
||||
html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-root {
|
||||
--m-rail-w: calc(env(safe-area-inset-right, 0px) + 100px);
|
||||
}
|
||||
|
||||
.dark .m-root {
|
||||
@@ -78,6 +81,7 @@
|
||||
--m-bg: #0A0A0C;
|
||||
--m-scr: radial-gradient(120% 80% at 50% -10%, #17171C 0%, #0C0C0F 55%, #08080A 100%);
|
||||
--m-glass: rgba(26,26,31,.6);
|
||||
--m-dock: rgba(26,26,31,.82);
|
||||
--m-gbr: rgba(255,255,255,.12);
|
||||
--m-card: rgba(24,24,29,.55);
|
||||
--m-cbr: rgba(255,255,255,.1);
|
||||
@@ -171,15 +175,13 @@
|
||||
|
||||
/* A form sheet on a wide window sits mid-screen, so it rises from the bottom
|
||||
edge of the window rather than from just below its own resting place. */
|
||||
@media (min-width: 600px) and (min-height: 501px) {
|
||||
@keyframes m-sheet-up {
|
||||
from { transform: translateY(calc(50dvh + 50%)); }
|
||||
to { transform: translateY(0); }
|
||||
}
|
||||
@keyframes m-sheet-down {
|
||||
from { transform: translateY(0); }
|
||||
to { transform: translateY(calc(50dvh + 50%)); }
|
||||
}
|
||||
@keyframes m-sheet-up-wide {
|
||||
from { transform: translateY(calc(50dvh + 50%)); }
|
||||
to { transform: translateY(0); }
|
||||
}
|
||||
@keyframes m-sheet-down-wide {
|
||||
from { transform: translateY(0); }
|
||||
to { transform: translateY(calc(50dvh + 50%)); }
|
||||
}
|
||||
.m-sheet-in { animation: m-sheet-in 260ms var(--ease-out-quint) both; }
|
||||
.m-sheet-out { animation: m-sheet-out 220ms var(--ease-drawer) both; }
|
||||
@@ -192,12 +194,14 @@
|
||||
.m-pop-in { animation: m-pop-in 220ms var(--ease-out-quint) both; }
|
||||
.m-toast-in { animation: m-toast-in 260ms var(--ease-out-quint) both; }
|
||||
.m-toast-out { animation: m-toast-out 220ms ease both; }
|
||||
@media (min-width: 600px) and (min-height: 501px) {
|
||||
.m-panel-in { animation: m-panel-in 320ms var(--ease-out-quint) both; }
|
||||
[dir='rtl'] .m-panel-in { animation-name: m-panel-in-rtl; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.m-panel-in, [dir='rtl'] .m-panel-in { animation: m-fade-in 120ms ease-out both; }
|
||||
}
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-sheet-up { animation-name: m-sheet-up-wide; }
|
||||
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-sheet-down { animation-name: m-sheet-down-wide; }
|
||||
}
|
||||
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-panel-in { animation: m-panel-in 320ms var(--ease-out-quint) both; }
|
||||
html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-panel-in { animation-name: m-panel-in-rtl; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-panel-in { animation: m-fade-in 120ms ease-out both; }
|
||||
}
|
||||
|
||||
/* Reduced motion: gentler, not zero (same rule the desktop keyframes follow). */
|
||||
@@ -631,6 +635,17 @@ html:has(.m-shell) body {
|
||||
overflow-x: clip;
|
||||
background-color: transparent;
|
||||
}
|
||||
/* The few routes without a phone screen of their own (a plugin's page, help,
|
||||
a trip's files) still render through PageShell. Inside the touch shell its
|
||||
desktop navbar, shown from 768px up, would stand over the rail and repeat the
|
||||
navigation, and --nav-h would keep 64px of room for it: the shell has its own
|
||||
navigation, so neither is there. */
|
||||
html:has(.m-shell) {
|
||||
--nav-h: 0px;
|
||||
}
|
||||
html:has(.m-shell) [data-desktop-navbar] {
|
||||
display: none;
|
||||
}
|
||||
html:has(.m-shell) .leaflet-control-zoom {
|
||||
display: none !important;
|
||||
}
|
||||
@@ -652,6 +667,13 @@ html:has(.m-shell) ::-webkit-scrollbar {
|
||||
margin-inline-start: var(--trip-map-inset, 0px);
|
||||
}
|
||||
|
||||
/* The strip under a floating dock (components/MDockScrim.tsx): solid across
|
||||
the gap below the dock, clear from about its middle up. */
|
||||
.m-dock-scrim {
|
||||
-webkit-mask-image: linear-gradient(to top, #000 calc(env(safe-area-inset-bottom, 0px) + 12px), transparent calc(env(safe-area-inset-bottom, 0px) + 40px));
|
||||
mask-image: linear-gradient(to top, #000 calc(env(safe-area-inset-bottom, 0px) + 12px), transparent calc(env(safe-area-inset-bottom, 0px) + 40px));
|
||||
}
|
||||
|
||||
/* A horizontal strip with more behind an edge fades out there
|
||||
(components/useEdgeFade.ts), so a cut chip reads as "the row goes on". */
|
||||
.m-fade-s,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { _resetOverlayStack, closeTopOverlay, hasOpenOverlay, useOverlay } from './overlayStack';
|
||||
import { _resetOverlayStack, closeTopOverlay, hasOpenOverlay, useHasOpenOverlay, useOverlay } from './overlayStack';
|
||||
|
||||
beforeEach(() => _resetOverlayStack());
|
||||
|
||||
@@ -33,4 +33,13 @@ describe('overlayStack', () => {
|
||||
expect(hasOpenOverlay()).toBe(false);
|
||||
expect(closeTopOverlay()).toBe(false);
|
||||
});
|
||||
|
||||
it('tells a component when an overlay opens and when the last one closes', () => {
|
||||
const watch = renderHook(() => useHasOpenOverlay());
|
||||
expect(watch.result.current).toBe(false);
|
||||
const sheet = renderHook(({ open }) => useOverlay(open, () => {}), { initialProps: { open: true } });
|
||||
expect(watch.result.current).toBe(true);
|
||||
sheet.rerender({ open: false });
|
||||
expect(watch.result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useLayoutEffect, useRef } from 'react';
|
||||
import { useEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';
|
||||
|
||||
/**
|
||||
* The overlays open on screen, newest last, so a way back closes the one on
|
||||
@@ -9,6 +9,16 @@ import { useEffect, useLayoutEffect, useRef } from 'react';
|
||||
type Close = () => void;
|
||||
const stack: { id: number; close: () => void }[] = [];
|
||||
let nextId = 1;
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function changed(): void {
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
|
||||
function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
}
|
||||
|
||||
/** Closes the overlay on top. False when none is open, so the caller goes back instead. */
|
||||
export function closeTopOverlay(): boolean {
|
||||
@@ -22,6 +32,11 @@ export function hasOpenOverlay(): boolean {
|
||||
return stack.length > 0;
|
||||
}
|
||||
|
||||
/** Whether an overlay is open, for a component that changes with it (the keyboard shortcuts). */
|
||||
export function useHasOpenOverlay(): boolean {
|
||||
return useSyncExternalStore(subscribe, hasOpenOverlay, () => false);
|
||||
}
|
||||
|
||||
/** Registers an overlay while `open`, with the way it closes. */
|
||||
export function useOverlay(open: boolean, close: Close): void {
|
||||
const closeRef = useRef(close);
|
||||
@@ -32,9 +47,11 @@ export function useOverlay(open: boolean, close: Close): void {
|
||||
if (!open) return;
|
||||
const entry = { id: nextId++, close: () => closeRef.current() };
|
||||
stack.push(entry);
|
||||
changed();
|
||||
return () => {
|
||||
const i = stack.findIndex((e) => e.id === entry.id);
|
||||
if (i >= 0) stack.splice(i, 1);
|
||||
changed();
|
||||
};
|
||||
}, [open]);
|
||||
}
|
||||
@@ -42,4 +59,5 @@ export function useOverlay(open: boolean, close: Close): void {
|
||||
/** Test helper. */
|
||||
export function _resetOverlayStack(): void {
|
||||
stack.length = 0;
|
||||
changed();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import MTripRail from './MTripRail'
|
||||
import { CollabSegment, CompactToggle, DocSyncButton, GlassSegment } from './MTripShellParts'
|
||||
import { edgeFadeClass, useEdgeFade } from '../../components/useEdgeFade'
|
||||
import { useShortcuts } from '../../keyboard/useShortcuts'
|
||||
import { tripCreateIntent } from '../../../components/Layout/useCreateAction'
|
||||
import MDockScrim from '../../components/MDockScrim'
|
||||
|
||||
/**
|
||||
* Mobile trip screen frame. Owns the chrome the design shares across every
|
||||
@@ -489,6 +491,8 @@ export default function MTripShell({
|
||||
else planner.handleSelectDay(next.id, true)
|
||||
}
|
||||
const dayKeys = trTab === 'plan' || trTab === 'roadtrip'
|
||||
// ⌘N creates what the tab on show creates, as the "+" does (MShellShortcuts lets go of it here).
|
||||
const createIntent = tripCreateIntent(String(tripId), trTab)
|
||||
useShortcuts('trip', [
|
||||
...keyTabs.map((tab, i) => ({ id: `tab-${tab.id}`, title: tab.label, key: String(i + 1), mod: true, run: () => setTrTab(tab.id) })),
|
||||
...(dayKeys && days.length > 1
|
||||
@@ -500,6 +504,7 @@ export default function MTripShell({
|
||||
...(split && MAP_TABS.has(trTab)
|
||||
? [{ id: 'pane', title: paneOpen ? t('mobileTrip.hidePane') : t('mobileTrip.showPane'), key: 's', ctrl: true, run: trTab === 'roadtrip' ? toggleRtView : toggleView }]
|
||||
: []),
|
||||
{ id: 'create', title: t(createIntent.labelKey), key: 'n', mod: true, run: () => void navigate(createIntent.to) },
|
||||
{ id: 'back', title: t('common.back'), key: '[', mod: true, run: () => void navigate('/dashboard') },
|
||||
])
|
||||
|
||||
@@ -891,7 +896,9 @@ export default function MTripShell({
|
||||
)}
|
||||
|
||||
{/* ── Bottom dock (replaces the global bottom nav on this screen) ── */}
|
||||
{!wide && <nav className="absolute inset-x-4 z-40 flex h-[62px] items-center justify-around rounded-[31px] border border-[color:var(--m-gbr)] bg-[color:var(--m-glass)] px-[14px] shadow-[0_16px_44px_-14px_rgba(0,0,0,.35)] backdrop-blur-[30px] backdrop-saturate-[1.8] bottom-[calc(env(safe-area-inset-bottom,0px)+12px)]">
|
||||
{/* A tab's list fades out under the dock rather than showing in the gap below it; a map runs to the edge. */}
|
||||
{!wide && !MAP_TABS.has(trTab) && <MDockScrim />}
|
||||
{!wide && <nav className="absolute inset-x-4 z-40 flex h-[62px] items-center justify-around rounded-[31px] border border-[color:var(--m-gbr)] bg-[color:var(--m-dock)] px-[14px] shadow-[0_16px_44px_-14px_rgba(0,0,0,.35)] backdrop-blur-[30px] backdrop-saturate-[1.4] bottom-[calc(env(safe-area-inset-bottom,0px)+12px)]">
|
||||
{dockTabs.map(({ id, icon: Icon }) => {
|
||||
// While More is open the dock points at More, not at the tab under it.
|
||||
const active = trTab === id && sheet?.id !== 'mehr'
|
||||
|
||||
Reference in New Issue
Block a user