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
Settings pages slide in from the right and back out like the iPhone's own Settings
Duarte Santoscbe5044cc44c
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsxindex 998c45ce3..4356deb82 100644--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@ -15,6 +15,7 @@ import { workoutVolume } from './lib/history.js'import { setSystemBarsLight } from './lib/system-bars.js'import { initBackButton } from './lib/back.js'import { installEdgeSwipeBack, BACK_PREVIEW_EVENT } from './lib/edge-swipe-back.js'+import { pageMotion } from './lib/page-motion.js'import { startWatchSync, bindWatchAppActions, patchSetIn } from './lib/watch-sync.js'import { stampWorkout } from './lib/sync-merge.js'import { logWeighIn } from './lib/bodyweight.js'@@ -281,7 +282,7 @@ function Shell() {lands it simply stays: same key, same parent, so React keeps it instead of mountingthe route again. */}<div id="app">- <Page key={loc.pathname} loc={loc} render={view} />+ <Page key={loc.pathname} loc={loc} render={view} motion={pageMotion(pathRef.current, loc.pathname, navType)} />{showPreview && <Page key={preview} loc={previewLoc(preview)} render={view} under scrollY={scrollPositions.get(preview) || 0} />}</div>{/* Outside #app: the view's fade-in animates a transform, and a fixed element inside it@@ -306,16 +307,17 @@ const previewLoc = pathname => ({ pathname, search: '', hash: '', state: null, konly shows. When the swipe lands it becomes the page in place (same element, same state, nosecond mount, no fade): the styles the gesture painted on it go, and App puts the window backat that scroll position in the same frame. */-function Page({ loc, render, under = false, scrollY = 0 }) {+function Page({ loc, render, under = false, scrollY = 0, motion = 'fade' }) {const ref = useRef(null)const wasUnder = useRef(under)+ const arrival = useRef(motion)const promoted = wasUnder.current && !underuseLayoutEffect(() => {if (under || !wasUnder.current) returnconst el = ref.currentif (el) { el.style.transform = ''; el.style.transition = ''; el.style.visibility = '' }}, [under])- return <div ref={ref} className={'page' + (under ? ' under' : wasUnder.current ? '' : ' vfade')}+ return <div ref={ref} className={'page' + (under ? ' under' : wasUnder.current ? '' : arrival.current === 'push' ? ' vpush' : arrival.current === 'pop' ? ' vpop' : ' vfade')}data-path={loc.pathname} data-promoted={promoted ? '' : undefined}aria-hidden={under || undefined} inert={under || undefined}><div className="page-in" style={under && scrollY ? { transform: `translateY(${-scrollY}px)` } : undefined}>diff --git a/frontend/src/index.css b/frontend/src/index.cssindex 7810ea0ea..989238617 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -180,6 +180,17 @@ body.no-tabbar.resting #app{padding-bottom:calc(96px + var(--sab))}.workout-end-spacer{height:0}@keyframes viewfade{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}#app > .page.vfade{animation:viewfade var(--med) var(--ease)}+/* Drilling into a settings page and back (App.jsx pageMotion): the iPhone's own push and pop.+ The page slides, the window never scrolls sideways while it does. */+@keyframes viewpush{from{transform:translateX(100%)}to{transform:none}}+@keyframes viewpop{from{transform:translateX(-28%);opacity:.7}to{transform:none;opacity:1}}+#app > .page.vpush{animation:viewpush .38s cubic-bezier(.32,.72,0,1);background:var(--bg);box-shadow:-12px 0 28px rgba(0,0,0,.18)}+#app > .page.vpop{animation:viewpop .34s cubic-bezier(.32,.72,0,1)}+[dir="rtl"] #app > .page.vpush{animation-name:viewpush-rtl;box-shadow:12px 0 28px rgba(0,0,0,.18)}+[dir="rtl"] #app > .page.vpop{animation-name:viewpop-rtl}+@keyframes viewpush-rtl{from{transform:translateX(-100%)}to{transform:none}}+@keyframes viewpop-rtl{from{transform:translateX(28%);opacity:.7}to{transform:none;opacity:1}}+#app:has(> .page.vpush),#app:has(> .page.vpop){overflow-x:clip}/* The page an edge swipe back returns to (App.jsx Page `under`, lib/edge-swipe-back.js): laidout where #app lays out a page, fixed under the current one, at the scroll position it wasleft at (.page-in is moved up by it), hidden until the finger has committed to the swipe. */diff --git a/frontend/src/lib/page-motion.js b/frontend/src/lib/page-motion.jsnew file mode 100644index 000000000..29d31fee8--- /dev/null+++ b/frontend/src/lib/page-motion.js@@ -0,0 +1,13 @@+/* How a page arrives, like Settings on the iPhone: going one level deeper (a settings page from+ Settings) slides it in from the right, going back up slides the parent in from the left, and+ everything else (tabs, a fresh load) keeps the soft fade. Read at mount, from the path it+ replaces. */+export function pageMotion(from, to, navType) {+ // The tabs are the top level: Home is '/', not the parent of every other tab.+ if (!from || from === to || from === '/' || to === '/') return 'fade'+ const deeper = to.startsWith(from.endsWith('/') ? from : from + '/')+ const upper = from.startsWith(to.endsWith('/') ? to : to + '/')+ if (deeper && navType !== 'POP') return 'push'+ if (upper && navType === 'POP') return 'pop'+ return 'fade'+}diff --git a/frontend/src/lib/page-motion.test.js b/frontend/src/lib/page-motion.test.jsnew file mode 100644index 000000000..24f470d23--- /dev/null+++ b/frontend/src/lib/page-motion.test.js@@ -0,0 +1,16 @@+import { expect, it } from 'vitest'+import { pageMotion } from './page-motion.js'++it('slides a settings page in from the right and its parent back in from the left', () => {+ expect(pageMotion('/settings', '/settings/workout', 'PUSH')).toBe('push')+ expect(pageMotion('/settings/workout', '/settings', 'POP')).toBe('pop')+})++it('keeps the fade for tabs, fresh loads, siblings and back into a deeper page', () => {+ expect(pageMotion(null, '/settings', 'POP')).toBe('fade')+ expect(pageMotion('/', '/settings', 'PUSH')).toBe('fade')+ expect(pageMotion('/settings/workout', '/settings/data', 'PUSH')).toBe('fade')+ expect(pageMotion('/settings', '/settings/workout', 'POP')).toBe('fade')+ expect(pageMotion('/settings/account', '/settings', 'PUSH')).toBe('fade')+ expect(pageMotion('/settingsx', '/settings', 'POP')).toBe('fade')+})