Skip to content

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.

UX: Scroll-Position bleibt bei View-Refresh (Zeitraum-Chips), Body-Scroll-Lock bei offenen Sheets, Sheet-Drag folgt sauber dem Finger

Duarte Santosb166e1aa454e
diff --git a/app/app.js b/app/app.js
index d35566311..e53966d65 100644
--- a/app/app.js
+++ b/app/app.js
@@ -252,6 +252,26 @@ function bindMediaToggle(media, ex) {
};
}
+/* ---------- body scroll lock (iOS-safe) while a modal is open ---------- */
+function currentScrollY() {
+ return 'slock' in document.body.dataset ? +document.body.dataset.slock : (window.scrollY || 0);
+}
+function lockBodyScroll() {
+ if ('slock' in document.body.dataset) return;
+ const y = window.scrollY || 0;
+ document.body.dataset.slock = y;
+ const st = document.body.style;
+ st.position = 'fixed'; st.top = -y + 'px'; st.left = '0'; st.right = '0'; st.width = '100%';
+}
+function unlockBodyScroll() {
+ if (!('slock' in document.body.dataset)) return;
+ const y = +document.body.dataset.slock;
+ delete document.body.dataset.slock;
+ const st = document.body.style;
+ st.position = st.top = st.left = st.right = st.width = '';
+ window.scrollTo(0, y);
+}
+
/* ---------- modal system ---------- */
const modalRoot = $('#modal-root');
let modalStack = [];
@@ -260,10 +280,11 @@ function openModal(html, kind) {
wrap.innerHTML = `<div class="mback"></div><div class="${kind || 'sheet'}">${kind === 'center' ? '' : '<div class="grab"></div>'}${html}</div>`;
modalRoot.appendChild(wrap);
modalRoot.classList.add('open');
+ lockBodyScroll();
const close = () => {
wrap.remove();
modalStack = modalStack.filter(m => m !== api);
- if (!modalRoot.children.length) modalRoot.classList.remove('open');
+ if (!modalRoot.children.length) { modalRoot.classList.remove('open'); unlockBodyScroll(); }
};
wrap.querySelector('.mback').addEventListener('click', () => { if (!wrap.dataset.lock) close(); });
const api = { el: wrap, close, lock: v => { wrap.dataset.lock = v ? '1' : ''; } };
@@ -279,10 +300,11 @@ function openModal(html, kind) {
if (startY === null) return;
delta = e.touches[0].clientY - startY;
if (delta > 0 && sh.scrollTop <= 0) {
+ e.preventDefault(); // only the sheet moves, never the page behind
sh.style.transition = 'none';
sh.style.transform = `translateY(${delta}px)`;
} else delta = 0;
- }, { passive: true });
+ }, { passive: false });
sh.addEventListener('touchend', () => {
if (startY === null) return;
sh.style.transition = 'transform .2s';
@@ -466,22 +488,27 @@ function nav(hash) { location.hash = hash; }
function route() { renderView(); updateTabbar(); }
function renderView() {
const h = (location.hash || '#home').slice(1);
+ // re-rendering the same view (range chips, toggles, …) keeps the scroll position;
+ // only an actual view change jumps to the top
+ const sameView = renderView._last === h;
+ renderView._last = h;
+ const keepY = sameView ? currentScrollY() : 0;
const [view, ...rest] = h.split('/');
clearInterval(elapsedInt);
closeAllModals();
const app = $('#app');
- window.scrollTo(0, 0);
- if (!USER && !isGuest()) return viewLogin(app);
- if (view === 'plan' && rest[0] === 'r') return viewRoutineEdit(app, rest[1]);
- switch (view) {
- case 'plan': return viewPlan(app);
- case 'workout': return viewWorkout(app);
- case 'stats': return viewStats(app);
- case 'library': return viewLibrary(app);
- case 'settings': return viewSettings(app);
- case 'history': return viewHistory(app);
- default: return viewHome(app);
+ if (!USER && !isGuest()) viewLogin(app);
+ else if (view === 'plan' && rest[0] === 'r') viewRoutineEdit(app, rest[1]);
+ else switch (view) {
+ case 'plan': viewPlan(app); break;
+ case 'workout': viewWorkout(app); break;
+ case 'stats': viewStats(app); break;
+ case 'library': viewLibrary(app); break;
+ case 'settings': viewSettings(app); break;
+ case 'history': viewHistory(app); break;
+ default: viewHome(app);
}
+ window.scrollTo(0, keepY);
}
window.addEventListener('hashchange', route);
document.querySelectorAll('#tabbar button').forEach(b => b.addEventListener('click', () => {
diff --git a/app/index.html b/app/index.html
index 1aeedbc04..41800efc8 100644
--- a/app/index.html
+++ b/app/index.html
@@ -13,7 +13,7 @@
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="icon-180.png">
<link rel="icon" type="image/png" href="icon-180.png">
-<link rel="stylesheet" href="style.css?v=6">
+<link rel="stylesheet" href="style.css?v=7">
</head>
<body>
<div id="app"><div style="padding-top:42vh;text-align:center;font-size:2.2rem">🏋️</div></div>
@@ -45,7 +45,7 @@
<div id="modal-root"></div>
<div id="toast"></div>
-<script src="data.js?v=6"></script>
-<script src="app.js?v=6"></script>
+<script src="data.js?v=7"></script>
+<script src="app.js?v=7"></script>
</body>
</html>
diff --git a/app/style.css b/app/style.css
index fb9d6e6e4..d5e8449e2 100644
--- a/app/style.css
+++ b/app/style.css
@@ -152,7 +152,8 @@ a{color:var(--acc)}
/* ---------- modal ---------- */
#modal-root{position:fixed;inset:0;z-index:100;display:none}
#modal-root.open{display:block}
-.mback{position:absolute;inset:0;background:rgba(0,0,0,.6);backdrop-filter:blur(3px)}
+.mback{position:absolute;inset:0;background:rgba(0,0,0,.6);backdrop-filter:blur(3px);
+ touch-action:none;overscroll-behavior:none}
.sheet{position:absolute;left:0;right:0;bottom:0;background:var(--bg2);
border-radius:22px 22px 0 0;padding:10px 18px calc(22px + var(--sab));
max-height:88vh;overflow-y:auto;-webkit-overflow-scrolling:touch;animation:slideup .28s;
diff --git a/app/sw.js b/app/sw.js
index c4c839859..6f5c1aba4 100644
--- a/app/sw.js
+++ b/app/sw.js
@@ -1,6 +1,6 @@
/* GymLog service worker — network-first for app shell, cache-first for media */
-const CACHE = 'gymlog-v6';
-const SHELL = ['./', 'index.html', 'style.css?v=6', 'app.js?v=6', 'data.js?v=6', 'manifest.json'];
+const CACHE = 'gymlog-v7';
+const SHELL = ['./', 'index.html', 'style.css?v=7', 'app.js?v=7', 'data.js?v=7', 'manifest.json'];
self.addEventListener('install', e => {
e.waitUntil(caches.open(CACHE).then(c => c.addAll(SHELL)).then(() => self.skipWaiting()));