Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
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
Duarte Santosd58a98e7681e
diff --git a/frontend/android/app/src/main/AndroidManifest.xml b/frontend/android/app/src/main/AndroidManifest.xmlindex 4860b3130..ea9aa08ba 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"><intent-filter><action android:name="android.intent.action.MAIN" />diff --git a/frontend/android/app/src/main/res/values/styles.xml b/frontend/android/app/src/main/res/values/styles.xmlindex be874e54a..ce261dbe5 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 @@<item name="windowActionBar">false</item><item name="windowNoTitle">true</item><item name="android:background">@null</item>+ <!-- Draw into the camera cutout like iOS does under the notch: the WebView then reports a+ real env(safe-area-inset-top) and the sheets keep clear of it (index.css --sat). -->+ <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item></style>diff --git a/frontend/src/components/Modals.jsx b/frontend/src/components/Modals.jsxindex acda36dee..397ccc4ab 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 || 0const b = document.body.styleb.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.cssindex 447dc4f2f..b7ad71075 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 handthe gesture to the page, which scrolled down instead. The row is 32px tall, so losing avertical 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.jsindex fd5753bee..005cb9562 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.currentconst 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.jsindex 1f2c75f99..c32434bc2 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.jsindex 8fd052451..2ba61023c 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 falseif (viewportDisplacement(win) <= 1) return false+ // The keyboard is gone but a text field may still hold focus: on WebKit tapping a <button>+ // (the set's tick, the RIR cell) does not blur the input, and iOS only puts the viewports+ // back once focus has left. Nothing is being typed with the keyboard down, so let it go.+ const active = win.document.activeElement+ if (isText(active)) active.blur?.()+ if (bodyPinned(win)) return realignPinned(win)win.scrollTo(win.scrollX || 0, win.scrollY || 0)return true}+const bodyPinned = win => win.document.body?.style?.position === 'fixed'++/** The same correction while Modals.jsx has the body pinned (`position:fixed; top:-y`): the+ * document has no scroll range then, so asking for the current position is a no-op and iOS+ * keeps the offset — the picker sheet left open after the keyboard closed. Let the page scroll+ * for one call, land it where the pin says it was, and pin it again. */+export function realignPinned(win = window) {+ const b = win.document.body?.style+ if (!b || b.position !== 'fixed') return false+ const top = b.top+ const y = Math.max(0, -parseFloat(top || '0') || 0)+ b.position = ''+ win.scrollTo(win.scrollX || 0, y)+ b.top = top+ b.position = 'fixed'+ return true+}+export function installViewportGuard(win = window) {const vv = win.visualViewportif (!vv) return () => {}diff --git a/frontend/src/lib/viewport-guard.test.js b/frontend/src/lib/viewport-guard.test.jsindex 334a66e18..b2a709b39 100644--- a/frontend/src/lib/viewport-guard.test.js+++ b/frontend/src/lib/viewport-guard.test.js@@ -1,8 +1,8 @@// @vitest-environment nodeimport { describe, it, expect, vi } from 'vitest'-import { installViewportGuard, realign, viewportDisplacement, keyboardOpen } from './viewport-guard.js'+import { installViewportGuard, realign, realignPinned, viewportDisplacement, keyboardOpen } from './viewport-guard.js'-function fakeWindow({ innerHeight = 800, vvHeight = 800, offsetTop = 0, pageTop = 0, scrollY = 0, active = null } = {}) {+function fakeWindow({ innerHeight = 800, vvHeight = 800, offsetTop = 0, pageTop = 0, scrollY = 0, active = null, bodyStyle = {} } = {}) {const listeners = {}const on = (map, type, fn) => { (map[type] = map[type] || []).push(fn) }const vv = {@@ -10,7 +10,7 @@ function fakeWindow({ innerHeight = 800, vvHeight = 800, offsetTop = 0, pageTopaddEventListener(t, fn) { on(this.listeners, t, fn) }, removeEventListener() {}}const doc = {- activeElement: active, listeners: {},+ activeElement: active, listeners: {}, body: { style: bodyStyle },addEventListener(t, fn) { on(this.listeners, t, fn) }, removeEventListener() {}}const win = {@@ -41,7 +41,32 @@ describe('viewport guard', () => {expect(realign(fakeWindow())).toBe(false) // alignedexpect(realign(fakeWindow({ offsetTop: 190, vvHeight: 480 }))).toBe(false) // keyboard still up- expect(realign(fakeWindow({ offsetTop: 190, active: { tagName: 'INPUT' } }))).toBe(false) // still typing+ })++ it('lets go of a text field that kept focus after the keyboard closed, then realigns', () => {+ // WebKit: tapping the set's tick does not blur the weight field. With the keyboard down+ // and the page displaced, that focus is what keeps iOS from putting the viewports back.+ const active = { tagName: 'INPUT', blur: vi.fn() }+ const w = fakeWindow({ offsetTop: 190, active })+ expect(realign(w)).toBe(true)+ expect(active.blur).toHaveBeenCalledTimes(1)+ expect(w.scrollTo).toHaveBeenCalledWith(0, 0)+ // an aligned page is left alone, focus included (a desktop browser mid-typing)+ const typing = { tagName: 'INPUT', blur: vi.fn() }+ expect(realign(fakeWindow({ active: typing }))).toBe(false)+ expect(typing.blur).not.toHaveBeenCalled()+ })++ it('unpins the body for one scroll when a sheet has it fixed, and pins it back where it was', () => {+ const bodyStyle = { position: 'fixed', top: '-240px' }+ const w = fakeWindow({ offsetTop: 190, scrollY: 0, bodyStyle })+ const seen = []+ w.scrollTo = vi.fn(() => seen.push({ ...bodyStyle }))+ expect(realign(w)).toBe(true)+ expect(w.scrollTo).toHaveBeenCalledWith(0, 240)+ expect(seen[0].position).toBe('') // the page could actually scroll at that moment+ expect(bodyStyle).toEqual({ position: 'fixed', top: '-240px' }) // and is pinned again after+ expect(realignPinned(fakeWindow())).toBe(false) // nothing pinned, nothing to do})it('fires when the keyboard has just closed, again after its animation, and on focusout', async () => {diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 5ba2e1c97..32de88ab2 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -809,6 +809,11 @@ function ActiveWorkout() {}const toggle = (idx, i, side) => {+ // Ticking a set ends the typing in that row: drop the keyboard before the rest timer, the+ // effort sheet or the next exercise moves in. WebKit keeps the input focused across the+ // button tap, and a focused input with its keyboard gone is what leaves the tab bar+ // mid-screen on iOS (lib/viewport-guard.js).+ if (typeof document !== 'undefined') { const a = document.activeElement; if (a && (a.tagName === 'INPUT' || a.tagName === 'TEXTAREA')) a.blur?.() }const m = modeAt(idx)const cardioEntry = m === 'cardio'let exJustDone = false, workoutDone = false, checked = false