diff --git a/client/src/mobile/MobileShell.tsx b/client/src/mobile/MobileShell.tsx index ad684d090..27dbfa8f6 100644 --- a/client/src/mobile/MobileShell.tsx +++ b/client/src/mobile/MobileShell.tsx @@ -89,7 +89,7 @@ export default function MobileShell({ isPhone, children }: MobileShellProps) { {!inTripPlanner && wide && ( )} -
{children}
+
{children}
{!inTripPlanner && !wide && ( diff --git a/client/src/mobile/mobile.css b/client/src/mobile/mobile.css index d7f11e834..5da25aa69 100644 --- a/client/src/mobile/mobile.css +++ b/client/src/mobile/mobile.css @@ -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. */ diff --git a/client/src/mobile/usePullToRefresh.test.tsx b/client/src/mobile/usePullToRefresh.test.tsx index 1664d113b..51b579eb3 100644 --- a/client/src/mobile/usePullToRefresh.test.tsx +++ b/client/src/mobile/usePullToRefresh.test.tsx @@ -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'); diff --git a/client/src/mobile/usePullToRefresh.ts b/client/src/mobile/usePullToRefresh.ts index 014b4f1b9..f7da58ccc 100644 --- a/client/src/mobile/usePullToRefresh.ts +++ b/client/src/mobile/usePullToRefresh.ts @@ -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; }; diff --git a/client/tests/unit/mobile/shellChrome.test.tsx b/client/tests/unit/mobile/shellChrome.test.tsx index 1718657cc..07bfa0031 100644 --- a/client/tests/unit/mobile/shellChrome.test.tsx +++ b/client/tests/unit/mobile/shellChrome.test.tsx @@ -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;'); + }); });