fix(mobile): keep the page clear of a Duo's status capsule and leave a scrolled column's pull to it

TestFlight feedback from an iPhone Duo:

- Folded, the status capsule stands in the right inset and ran over the hero
  card's actions; the page now keeps clear of the side insets as iOS asks
  (.m-page), and a floating bar keeps a little air next to an inset.
- Unfolded, the top bar ignored the trailing inset and the capsule sat on the
  avatar; on a wide window the bars now end before it, by their box, so a
  bar that centres itself still does.
- Dragging the dashboard's second column back up refreshed the page: a pull
  that starts inside a box scrolled on its own now belongs to that box.
This commit is contained in:
Maurice
2026-11-14 16:19:44 +01:00
parent d541bfa838
commit e6f35158c5
5 changed files with 124 additions and 5 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) {
{!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>
<div ref={pageRef} className="m-page flex-1 wide:ps-[var(--m-rail-w)]">{children}</div>
<MEdgeBack target={pageRef} enabled={edgeBack} />
{!inTripPlanner && !wide && (
<ErrorBoundary boundaryId="chrome:m-bottom-nav" fallback={null}><MBottomNav /></ErrorBoundary>
+37 -1
View File
@@ -70,6 +70,11 @@
--m-safe-l: max(env(safe-area-inset-left, 0px), var(--trek-native-safe-left, 0px));
--m-safe-r: max(env(safe-area-inset-right, 0px), var(--trek-native-safe-right, 0px));
--m-safe-top: calc(var(--m-safe-t) + 12px);
/* A side inset plus a little air, for the floating bars: next to a Duo's
* status capsule a bar that ends exactly at the inset reads as touching it.
* Without an inset the air is 0 too (min() of 0 and 8px). */
--m-safe-l-gap: calc(var(--m-safe-l) + min(var(--m-safe-l), 8px));
--m-safe-r-gap: calc(var(--m-safe-r) + min(var(--m-safe-r), 8px));
/* The navigation rail's share of the leading edge (wide windows only), what
* every full-width fixed bar and the page column start after. */
--m-rail-w: 0px;
@@ -583,11 +588,42 @@ html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-
On a wide window the rail takes the leading side and a bar may centre itself
(mx-auto). */
html:not(:has(.m-shell[data-size='wide'], .m-shell[data-size='split'])) :is(.m-bar-x, .m-span-x) {
margin-inline: var(--m-safe-l, 0px) var(--m-safe-r, 0px);
margin-inline: var(--m-safe-l-gap, 0px) var(--m-safe-r-gap, 0px);
}
html[dir='rtl']:not(:has(.m-shell[data-size='wide'], .m-shell[data-size='split'])) :is(.m-bar-x, .m-span-x) {
margin-inline: var(--m-safe-r-gap, 0px) var(--m-safe-l-gap, 0px);
}
/* On a wide window the rail holds the leading side; the trailing side still
has the screen's inset, which on an unfolded Duo is its status capsule, so
the top bar's avatar no longer sits under it (TestFlight feedback). The box
the bar is placed in ends earlier rather than the bar taking a margin, so a
bar that centres itself (mx-auto) still does. */
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-bar-x {
inset-inline-end: calc(16px + var(--m-safe-r-gap, 0px));
}
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-span-x {
inset-inline-end: var(--m-safe-r-gap, 0px);
}
html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-bar-x {
inset-inline-end: calc(16px + var(--m-safe-l-gap, 0px));
}
html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-span-x {
inset-inline-end: var(--m-safe-l-gap, 0px);
}
/* The page itself keeps clear of the sides' safe area, as iOS asks of every
app: on a Duo the status capsule stands in the right inset, and cards under
the top bar ran beneath it (TestFlight feedback). Margins, so the rail's
wide:ps on the same element stays; fixed layers are the window's and keep
their own rules. The rail already takes the leading inset on a wide window. */
.m-page {
margin-inline: var(--m-safe-l, 0px) var(--m-safe-r, 0px);
}
html[dir='rtl'] .m-page {
margin-inline: var(--m-safe-r, 0px) var(--m-safe-l, 0px);
}
html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-page {
margin-inline-start: 0;
}
/* A screen whose background is a map reaches under the rail: the map runs to
the window's edge and the rail floats over it like the top controls do. Its
own bars then keep to the page column with m-bar-x / m-span-x. */
+45 -1
View File
@@ -6,7 +6,7 @@ vi.mock('./overlayStack', () => ({ hasOpenOverlay: vi.fn(() => false) }));
import { tickHaptic } from '../native/haptics';
import { hasOpenOverlay } from './overlayStack';
import { usePullToRefresh } from './usePullToRefresh';
import { insideScrolledBox, usePullToRefresh } from './usePullToRefresh';
function touch(type: string, x = 0, y = 0) {
const event = new Event(type, { cancelable: true });
@@ -81,6 +81,50 @@ describe('usePullToRefresh', () => {
expect(el.style.transform).toBe('');
});
it('leaves a pull that starts in a scrolled column of its own to that column', () => {
const { onRefresh } = setup();
const column = document.createElement('div');
column.style.overflowY = 'auto';
Object.defineProperty(column, 'scrollTop', { value: 300, configurable: true });
Object.defineProperty(column, 'scrollHeight', { value: 2000, configurable: true });
Object.defineProperty(column, 'clientHeight', { value: 600, configurable: true });
const card = document.createElement('div');
column.appendChild(card);
document.body.appendChild(column);
const fire = (type: string, y: number) => {
const event = new Event(type, { cancelable: true, bubbles: true });
Object.defineProperty(event, 'touches', { value: type === 'touchend' ? [] : [{ clientX: 100, clientY: y }] });
act(() => {
card.dispatchEvent(event);
});
return event;
};
fire('touchstart', 100);
expect(fire('touchmove', 400).defaultPrevented).toBe(false);
fire('touchend', 400);
vi.runAllTimers();
expect(onRefresh).not.toHaveBeenCalled();
column.remove();
});
it('counts a box as scrolled only when it scrolls on its own and is off its top', () => {
const box = document.createElement('div');
const inner = document.createElement('div');
box.appendChild(inner);
document.body.appendChild(box);
Object.defineProperty(box, 'scrollHeight', { value: 2000, configurable: true });
Object.defineProperty(box, 'clientHeight', { value: 600, configurable: true });
Object.defineProperty(box, 'scrollTop', { value: 50, configurable: true });
expect(insideScrolledBox(inner, null)).toBe(false);
box.style.overflowY = 'auto';
expect(insideScrolledBox(inner, null)).toBe(true);
expect(insideScrolledBox(inner, box)).toBe(false);
Object.defineProperty(box, 'scrollTop', { value: 0, configurable: true });
expect(insideScrolledBox(inner, null)).toBe(false);
expect(insideScrolledBox(null, null)).toBe(false);
box.remove();
});
it('reads the scroll position of its own scroll box when given one', () => {
const el = document.createElement('div');
const scroller = document.createElement('div');
+20
View File
@@ -13,6 +13,25 @@ export type PullState = { distance: number; refreshing: boolean; armed: boolean
/** The screen's own refresh reports its failures (a toast, its error state); the pull only lets go. */
function refreshFailed(): void {}
/**
* Whether the touch starts inside a box that scrolls on its own and is not at
* its top, such as the second column of the dashboard on an unfolded Duo or an
* iPad. That pull scrolls the box back up; it is no refresh of the page
* (TestFlight feedback: dragging the right column back up refreshed instead).
*/
export function insideScrolledBox(target: EventTarget | null, page: Element | null): boolean {
for (
let el = target instanceof Element ? target : null;
el && el !== page && el !== document.body;
el = el.parentElement
) {
if (el.scrollTop <= 0 || el.scrollHeight <= el.clientHeight) continue;
const overflow = getComputedStyle(el).overflowY;
if (overflow === 'auto' || overflow === 'scroll') return true;
}
return false;
}
/**
* Pull-to-refresh on a page whose scroller is the window, as the mobile
* dashboard is. A downward drag that starts at the very top moves `contentRef`
@@ -63,6 +82,7 @@ export function usePullToRefresh(
const onStart = (e: TouchEvent) => {
if (busy || e.touches.length !== 1 || scrolled() > 0 || hasOpenOverlay()) return;
if (insideScrolledBox(e.target, scrollerRef?.current ?? null)) return;
start = { x: e.touches[0].clientX, y: e.touches[0].clientY };
pulling = false;
};
+21 -2
View File
@@ -63,13 +63,32 @@ describe('safe area in the touch shell', () => {
it('FE-MOB-CHROME-005: without the rail the floating bars keep clear of a side inset, such as a camera in a corner', () => {
const narrow = "html:not(:has(.m-shell[data-size='wide'], .m-shell[data-size='split'])) :is(.m-bar-x, .m-span-x) {";
const rule = css.split(narrow)[1]?.split('}')[0] ?? '';
expect(rule).toContain('margin-inline: var(--m-safe-l, 0px) var(--m-safe-r, 0px);');
expect(rule).toContain('margin-inline: var(--m-safe-l-gap, 0px) var(--m-safe-r-gap, 0px);');
// The insets are the screen's: right to left takes them the other way round.
const rtl = css.split(`html[dir='rtl']${narrow.slice('html'.length)}`)[1]?.split('}')[0] ?? '';
expect(rtl).toContain('margin-inline: var(--m-safe-r, 0px) var(--m-safe-l, 0px);');
expect(rtl).toContain('margin-inline: var(--m-safe-r-gap, 0px) var(--m-safe-l-gap, 0px);');
// On a wide window the bars keep no side margin, so mx-auto still centres them.
for (const cls of ['m-bar-x', 'm-span-x']) {
expect(css.split(`\n.${cls} {`)[1]?.split('}')[0] ?? '').not.toContain('margin');
}
});
it('FE-MOB-CHROME-006: a side inset gets a little air, and none where there is no inset', () => {
expect(css).toContain('--m-safe-r-gap: calc(var(--m-safe-r) + min(var(--m-safe-r), 8px));');
expect(css).toContain('--m-safe-l-gap: calc(var(--m-safe-l) + min(var(--m-safe-l), 8px));');
});
it('FE-MOB-CHROME-007: on a wide window the bars end before the trailing inset, by their box, not a margin', () => {
const wide = "html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-bar-x {";
expect(css.split(wide)[1]?.split('}')[0] ?? '').toContain('inset-inline-end: calc(16px + var(--m-safe-r-gap, 0px));');
const rtl = `html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-bar-x {`;
expect(css.split(rtl)[1]?.split('}')[0] ?? '').toContain('inset-inline-end: calc(16px + var(--m-safe-l-gap, 0px));');
});
it('FE-MOB-CHROME-008: the page keeps clear of the side insets, the leading one left to the rail on a wide window', () => {
expect(css.split('\n.m-page {')[1]?.split('}')[0] ?? '').toContain('margin-inline: var(--m-safe-l, 0px) var(--m-safe-r, 0px);');
expect(css.split("html[dir='rtl'] .m-page {")[1]?.split('}')[0] ?? '').toContain('margin-inline: var(--m-safe-r, 0px) var(--m-safe-l, 0px);');
const wide = "html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-page {";
expect(css.split(wide)[1]?.split('}')[0] ?? '').toContain('margin-inline-start: 0;');
});
});