From d58a98e7681edbc5cdc65875de47194416a4a802 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Sat, 12 Sep 2026 13:11:17 +0200 Subject: [PATCH] Phone layout: chip strips no longer scroll the page, sheets stop short of the Dynamic Island, tab bar stays at the bottom after the keyboard - useRevealActiveChip sets the strip's own scrollLeft instead of scrollIntoView, which walked every scrollable ancestor and jumped the page when the strip sat above the fold; .chips contain overscroll on both axes. - Every .sheet cap (and .center) carries env(safe-area-inset-top); the dead -webkit-overflow-scrolling is gone. - viewport-guard: with the keyboard down and the page displaced, a text field that kept focus (WebKit does not blur on button taps) is blurred and the correction runs; while Modals has the body pinned it unpins for one scroll and pins back where it was. Modals blurs a page field when a sheet opens; ticking a set blurs the row's input. - Android: shortEdges cutout mode so --sat is real, adjustResize for the keyboard. --- .../android/app/src/main/AndroidManifest.xml | 1 + .../app/src/main/res/values/styles.xml | 3 ++ frontend/src/components/Modals.jsx | 6 +++ frontend/src/index.css | 20 ++++++---- frontend/src/lib/use-sheet-keyboard.js | 27 ++++++++++++-- frontend/src/lib/use-sheet-keyboard.test.js | 37 ++++++++++++++++++- frontend/src/lib/viewport-guard.js | 25 ++++++++++++- frontend/src/lib/viewport-guard.test.js | 33 +++++++++++++++-- frontend/src/views/Workout.jsx | 5 +++ 9 files changed, 140 insertions(+), 17 deletions(-) diff --git a/frontend/android/app/src/main/AndroidManifest.xml b/frontend/android/app/src/main/AndroidManifest.xml index 4860b31..ea9aa08 100644 --- a/frontend/android/app/src/main/AndroidManifest.xml +++ b/frontend/android/app/src/main/AndroidManifest.xml @@ -13,6 +13,7 @@ android:label="@string/title_activity_main" android:theme="@style/AppTheme.NoActionBarLaunch" android:launchMode="singleTask" + android:windowSoftInputMode="adjustResize" android:exported="true"> diff --git a/frontend/android/app/src/main/res/values/styles.xml b/frontend/android/app/src/main/res/values/styles.xml index be874e5..ce261db 100644 --- a/frontend/android/app/src/main/res/values/styles.xml +++ b/frontend/android/app/src/main/res/values/styles.xml @@ -13,6 +13,9 @@ false true @null + + shortEdges diff --git a/frontend/src/components/Modals.jsx b/frontend/src/components/Modals.jsx index acda36d..397ccc4 100644 --- a/frontend/src/components/Modals.jsx +++ b/frontend/src/components/Modals.jsx @@ -164,6 +164,12 @@ export default function Modals() { }, [sheets.length]) useEffect(() => { if (!sheets.length) return + // A text field on the page behind (a set's weight, the Library search) keeps focus when a + // button opens a sheet — WebKit does not blur on button taps — and its keyboard then + // stays up under the sheet, or leaves the viewport displaced when it finally goes. The + // sheet owns the screen now; a field inside the sheet (the picker search) is left alone. + const a = document.activeElement + if (a && (a.tagName === 'INPUT' || a.tagName === 'TEXTAREA' || a.isContentEditable) && !a.closest?.('#modal-root')) a.blur?.() const y = window.scrollY || 0 const b = document.body.style b.position = 'fixed'; b.top = -y + 'px'; b.left = '0'; b.right = '0'; b.width = '100%' diff --git a/frontend/src/index.css b/frontend/src/index.css index 447dc4f..b7ad710 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -115,7 +115,7 @@ body{ background:var(--bg);color:var(--label); font-family:-apple-system,BlinkMacSystemFont,'SF Pro Text','SF Pro Display','Segoe UI',Roboto,system-ui,sans-serif; font-size:17px;line-height:1.29;letter-spacing:-.01em; - min-height:100vh;overscroll-behavior-y:none;overflow-x:clip; + min-height:100vh;min-height:100dvh;overscroll-behavior-y:none;overflow-x:clip; -webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale; touch-action:manipulation; font-variant-numeric:tabular-nums; @@ -426,7 +426,7 @@ h4.sec{ /* ---------------------------------------------------------------- chips -- */ .chips{ display:flex;gap:7px;overflow-x:auto;padding-bottom:2px; - scrollbar-width:none;-webkit-overflow-scrolling:touch; + scrollbar-width:none; } .chips::-webkit-scrollbar{display:none} /* horizontal strips: keep a sideways overscroll from chaining to the page and leave a @@ -434,9 +434,10 @@ h4.sec{ (touch-action:pan-x): on a phone a slightly diagonal swipe along the chips used to hand the gesture to the page, which scrolled down instead. The row is 32px tall, so losing a vertical scroll that happens to start on it costs nothing; the ~130px heatmap wrap keeps - both axes, there the trade-off goes the other way. */ + both axes, there the trade-off goes the other way. The chips contain both axes: once a + strip is at its end, a diagonal drag must not chain into the page either. */ .chips,.hm-wrap{overscroll-behavior-x:contain;scroll-padding-inline:16px} -.chips{touch-action:pan-x} +.chips{touch-action:pan-x;overscroll-behavior:contain} .chip{ flex:none;padding:6px 13px;border-radius:99px;background:var(--surface); font-size:14px;font-weight:400;color:var(--label);text-transform:capitalize; @@ -860,14 +861,18 @@ body.chips-dragging *{cursor:inherit} position:absolute;left:0;right:0;bottom:0;background:var(--bg-el); border-radius:var(--r-xl) var(--r-xl) 0 0; padding:8px 18px calc(20px + var(--sab)); - max-height:90vh;max-height:min(90vh,calc(100dvh - 8px)); - overflow-y:auto;-webkit-overflow-scrolling:touch;scroll-padding-bottom:calc(20px + var(--sab)); + /* A tall sheet stops short of the status bar / Dynamic Island: every cap carries the top + safe-area inset, which the layout viewport does not (viewport-fit=cover). */ + max-height:90vh;max-height:min(90vh,calc(100dvh - var(--sat) - 8px)); + overflow-y:auto;scroll-padding-bottom:calc(20px + var(--sab)); animation:sheetup .34s var(--ease); overscroll-behavior:contain;touch-action:pan-y;will-change:transform; } .sheet:has(.picker-search){ bottom:var(--picker-keyboard-bottom,0px); - max-height:min(90vh,calc(100dvh - 8px),calc(var(--picker-visual-height,100vh) - 8px)); + /* with the keyboard up the sheet is capped by the visual viewport — which still starts + under the notch, hence the inset here too */ + max-height:min(90vh,calc(100dvh - var(--sat) - 8px),calc(var(--picker-visual-height,100vh) - var(--sat) - 8px)); } :root[data-theme="light"] .sheet{background:var(--bg)} @keyframes sheetup{from{transform:translateY(100%)}to{transform:none}} @@ -881,6 +886,7 @@ body.chips-dragging *{cursor:inherit} .center{ position:absolute;left:50%;top:50%;transform:translate(-50%,-50%); width:min(84vw,300px);background:var(--bg-el);border-radius:var(--r-lg);padding:20px; + max-height:calc(100dvh - 2*var(--sat) - 24px);overflow-y:auto; box-shadow:0 20px 60px -12px rgba(0,0,0,.5); animation:pop .28s var(--ease); } diff --git a/frontend/src/lib/use-sheet-keyboard.js b/frontend/src/lib/use-sheet-keyboard.js index fd5753b..005cb95 100644 --- a/frontend/src/lib/use-sheet-keyboard.js +++ b/frontend/src/lib/use-sheet-keyboard.js @@ -47,14 +47,33 @@ export function useSheetKeyboard(inputRef, enabled = true) { } /* Chip strips scroll sideways, and a filter set from code ("★ Chosen", a reset) can land the - active chip off-screen. Pull it into view along the strip only — block:'nearest' never moves - the page when the strip is already visible, which is the case for every strip we have. */ + active chip off-screen. Pull it into view along the strip only. This used to be + scrollIntoView({block:'nearest'}), which also walks every scrollable ancestor: with the + strip scrolled above the fold (Library, halfway down the list) a tap on a chip made the + whole page jump up to show the row — the "swiping the chips scrolls the page" bug. Setting + the strip's own scrollLeft cannot move anything but the strip. + + `pad` mirrors scroll-padding-inline in index.css so a revealed chip is not glued to the edge. */ +export function revealChip(strip, chip, pad = 16) { + if (!strip || !chip || typeof strip.getBoundingClientRect !== 'function' || typeof chip.getBoundingClientRect !== 'function') return false + const s = strip.getBoundingClientRect(), c = chip.getBoundingClientRect() + const width = strip.clientWidth || s.width || 0 + if (!width) return false + const left = c.left - s.left + (strip.scrollLeft || 0) // chip's offset inside the strip's content + const right = left + c.width + let next = strip.scrollLeft || 0 + if (left - pad < next) next = Math.max(0, left - pad) + else if (right + pad > next + width) next = right + pad - width + if (next === (strip.scrollLeft || 0)) return false + strip.scrollLeft = next + return true +} + export function useRevealActiveChip(stripRef, active) { useEffect(() => { const strip = stripRef.current const chip = strip?.querySelector?.('.chip.on') - if (!chip || typeof chip.scrollIntoView !== 'function') return - chip.scrollIntoView({ inline: 'nearest', block: 'nearest' }) + if (chip) revealChip(strip, chip) }, [stripRef, active]) } diff --git a/frontend/src/lib/use-sheet-keyboard.test.js b/frontend/src/lib/use-sheet-keyboard.test.js index 1f2c75f..c32434b 100644 --- a/frontend/src/lib/use-sheet-keyboard.test.js +++ b/frontend/src/lib/use-sheet-keyboard.test.js @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest' -import { tappable } from './use-sheet-keyboard.js' +import { tappable, revealChip } from './use-sheet-keyboard.js' const keyEvent = (key, target) => { const ev = { key, target, currentTarget: target, preventDefault: vi.fn() } @@ -38,3 +38,38 @@ describe('tappable', () => { expect(tappable(undefined)).toEqual({}) }) }) + +// A strip is 300px wide showing content from scrollLeft; chips are 80px wide, 8px apart. +const strip = (scrollLeft = 0, width = 300) => ({ + scrollLeft, clientWidth: width, + getBoundingClientRect: () => ({ left: 20, width }) +}) +const chipAt = (contentX, strip) => ({ + getBoundingClientRect: () => ({ left: 20 + contentX - strip.scrollLeft, width: 80 }) +}) + +describe('revealChip', () => { + it('scrolls the strip, and only the strip, until the active chip is inside it', () => { + const s = strip(0) + expect(revealChip(s, chipAt(500, s))).toBe(true) + expect(s.scrollLeft).toBe(500 + 80 + 16 - 300) // chip's right edge plus the padding at the right edge + const back = strip(400) + expect(revealChip(back, chipAt(100, back))).toBe(true) + expect(back.scrollLeft).toBe(100 - 16) // padding at the left edge + }) + + it('leaves a visible chip where it is', () => { + const s = strip(100) + expect(revealChip(s, chipAt(200, s))).toBe(false) + expect(s.scrollLeft).toBe(100) + }) + + it('never reaches for the page: no scrollIntoView, nothing without a measurable strip', () => { + const s = strip(0) + const chip = Object.assign(chipAt(900, s), { scrollIntoView: vi.fn() }) + revealChip(s, chip) + expect(chip.scrollIntoView).not.toHaveBeenCalled() + expect(revealChip(null, chip)).toBe(false) + expect(revealChip({ scrollLeft: 0, clientWidth: 0, getBoundingClientRect: () => ({ left: 0, width: 0 }) }, chip)).toBe(false) + }) +}) diff --git a/frontend/src/lib/viewport-guard.js b/frontend/src/lib/viewport-guard.js index 8fd0524..2ba6102 100644 --- a/frontend/src/lib/viewport-guard.js +++ b/frontend/src/lib/viewport-guard.js @@ -36,12 +36,35 @@ export function keyboardOpen(win = window) { /** Realign the viewports if iOS left them apart. Returns true when a correction was issued. */ export function realign(win = window) { if (keyboardOpen(win)) return false - if (isText(win.document.activeElement)) return false if (viewportDisplacement(win) <= 1) return false + // The keyboard is gone but a text field may still hold focus: on WebKit tapping a