From 6234ec6124208969512f4dbc4dce64fc2a1c2d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20B=C3=B6hm?= Date: Sat, 7 Nov 2026 10:29:42 +0000 Subject: [PATCH] Never move the bottom bar while scrolling (26.11.32) The keyboard fix from 26.11.18 translated the bar on every visualViewport resize and scroll. In Safari the address bar collapses and expands while scrolling, iOS reports it late, and the bar slid along. The correction now runs only in the home-screen app, only for one second after the keyboard closes and only for gaps over 40 px; the first touch or wheel ends it. A browser test fakes the iOS viewport and fails with the old hook. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q --- CLAUDE.md | 14 +++-- OlaresManifest.yaml | 4 +- e2e/leiste.spec.ts | 101 +++++++++++++++++++++++++++++++++++++ lib/use-keyboard-nav.ts | 67 +++++++++++++++++++----- olares/Chart.yaml | 4 +- olares/OlaresManifest.yaml | 4 +- olares/markt/26.11.32.md | 5 ++ playwright.config.ts | 8 ++- tests/keyboard-gap.test.ts | 20 ++++++++ 9 files changed, 204 insertions(+), 23 deletions(-) create mode 100644 e2e/leiste.spec.ts create mode 100644 olares/markt/26.11.32.md create mode 100644 tests/keyboard-gap.test.ts diff --git a/CLAUDE.md b/CLAUDE.md index e8417d3..9cdc88e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -7,7 +7,7 @@ > **Plattform:** Olares One (Kubernetes), Repo und CI auf Gitea — kein Supabase, > kein Vercel (E-0001). Eigene Gestaltung, nicht AImighty (E-0002). > Verteilung über den Markt, Repo öffentlich (E-0005). -> **Status:** 26.11.31 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut: +> **Status:** 26.11.32 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut: > Anmeldung (Passkeys, Kinder mit Gerät + PIN), Gerichte (Link, Kochbuchfoto, AI über den > Olares Router), Wünschen, Plan, Einkaufsliste (Echtzeit, offline), Kochmodus mit > Bewertung, Web-App; Einzahl bei Stück-Mengen (26.11.15), Preise und Kosten mit Ampel @@ -445,9 +445,15 @@ Vorlagen ersetzt. `tests/seed.test.ts` prüft die Dateien. Ein Haushalt - iOS lässt eine feste Leiste nach dem Schließen der Tastatur oft dort stehen, wo die Tastatur endete (Kai, 7.11.2026). `components/app-nav.tsx` nutzt deshalb - `useKeyboardSafeNav` (`lib/use-keyboard-nav.ts`): beim Tippen `hidden`, danach am - `visualViewport` ausgerichtet (`translateY` um die Lücke) und ein Scroll auf der - Stelle. Eine neue feste Leiste unten nutzt denselben Haken. `e2e/pwa.spec.ts` wacht. + `useKeyboardSafeNav` (`lib/use-keyboard-nav.ts`): beim Tippen `hidden`, danach ein + Scroll auf der Stelle und **nur eine Sekunde lang** `translateY` um die Lücke + (`keyboardGap`, ab 40 px), nur in der Web-App vom Home-Bildschirm; die erste Berührung + beendet es. Eine neue feste Leiste unten nutzt denselben Haken. +- **Nie beim Scrollen verschieben** (26.11.32): Bis 26.11.31 hing die Korrektur an jedem + `visualViewport`-Ereignis, und die Leiste rutschte beim Scrollen mit, wenn Safaris + Adressleiste ein- und ausfuhr. Kein Listener auf `scroll` des sichtbaren Bereichs. + `e2e/leiste.spec.ts` täuscht den iOS-Sichtbereich vor und wacht darüber (fällt mit dem + alten Haken durch). - Feste Knopfleisten unten nehmen `sticky bottom-[var(--nav-space)]` (seit 26.11.26), nie einen festen Abstand: Beim Tippen setzt der Haken `data-typing` an ``, dann ist `--nav-space` 0 und die Knöpfe sitzen über der Tastatur. diff --git a/OlaresManifest.yaml b/OlaresManifest.yaml index 6ab6d9a..c281817 100644 --- a/OlaresManifest.yaml +++ b/OlaresManifest.yaml @@ -21,7 +21,7 @@ metadata: title: What's cooking? description: The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box. icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png - version: 26.11.31 + version: 26.11.32 categories: - Applications @@ -61,7 +61,7 @@ permission: appData: true spec: - versionName: '26.11.31' + versionName: '26.11.32' featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png promoteImage: diff --git a/e2e/leiste.spec.ts b/e2e/leiste.spec.ts new file mode 100644 index 0000000..db8ed2d --- /dev/null +++ b/e2e/leiste.spec.ts @@ -0,0 +1,101 @@ +import { expect, test, type Page } from "@playwright/test"; + +// Die untere Leiste bleibt unten (26.11.32, Kai: „rutscht beim Scrollen mit nach +// oben“). Chromium fährt keine Adressleiste ein und hat keine Tastatur; deshalb +// täuscht der Test einen iPhone-Sichtbereich vor (visualViewport, Web-App vom +// Home-Bildschirm) und bewegt ihn wie iOS beim Scrollen und nach dem Tippen. +test.beforeEach(async ({ page }) => { + await page.addInitScript(() => { + const vv = new EventTarget() as EventTarget & Record; + const w = window as unknown as { __vv: typeof vv; __extra: number; __top: number }; + w.__extra = 0; + w.__top = 0; + const props: Record number> = { + height: () => window.innerHeight + w.__extra, + width: () => window.innerWidth, + offsetTop: () => w.__top, + offsetLeft: () => 0, + pageTop: () => window.scrollY + w.__top, + pageLeft: () => 0, + scale: () => 1, + }; + for (const [k, get] of Object.entries(props)) + Object.defineProperty(vv, k, { get }); + Object.defineProperty(window, "visualViewport", { get: () => vv, configurable: true }); + w.__vv = vv; + const media = window.matchMedia.bind(window); + window.matchMedia = (q: string) => + q.includes("standalone") ? ({ matches: true, media: q, onchange: null, addListener() {}, removeListener() {}, addEventListener() {}, removeEventListener() {}, dispatchEvent: () => false } as MediaQueryList) : media(q); + }); +}); + +/** iOS bewegt den sichtbaren Bereich: um extra Pixel größer, um top verschoben. */ +async function moveViewport(page: Page, extra: number, top = 0) { + await page.evaluate( + ({ extra, top }) => { + const w = window as unknown as { __vv: EventTarget; __extra: number; __top: number }; + w.__extra = extra; + w.__top = top; + w.__vv.dispatchEvent(new Event("resize")); + w.__vv.dispatchEvent(new Event("scroll")); + }, + { extra, top }, + ); +} + +async function navAtBottom(page: Page) { + const nav = page.getByRole("navigation", { name: "Navigation" }); + await expect(nav).toBeVisible(); + const { bottom, inner, transform } = await nav.evaluate((el) => ({ + bottom: Math.round(el.getBoundingClientRect().bottom), + inner: window.innerHeight, + transform: (el as HTMLElement).style.transform, + })); + expect(transform).toBe(""); + expect(bottom).toBe(inner); +} + +test("scrolling never moves the bar, even while the address bar comes and goes", async ({ page }) => { + await page.goto("/mehr"); + await navAtBottom(page); + const height = await page.evaluate(() => document.documentElement.scrollHeight); + for (const [y, extra, top] of [ + [300, 80, 0], // Adressleiste fährt ein + [900, 80, 0], + [height, 120, 40], // Gummiband am Ende + [400, 0, 0], // Adressleiste wieder da + [0, 0, -30], // Gummiband oben + ]) { + await page.mouse.wheel(0, y! - (await page.evaluate(() => window.scrollY))); + await moveViewport(page, extra!, top!); + await page.waitForTimeout(50); + await navAtBottom(page); + } +}); + +test("after typing, a stale gap is bridged briefly and dropped at the first touch", async ({ page }) => { + await page.goto("/mehr"); + const field = page.locator("#kid-name"); + await field.focus(); + await expect(page.getByRole("navigation", { name: "Navigation" })).toBeHidden(); // beim Tippen weg + // iOS lässt das Layout nach dem Schließen der Tastatur 300 px zu kurz stehen. + await moveViewport(page, 300); + await field.blur(); + const nav = page.getByRole("navigation", { name: "Navigation" }); + await expect(nav).toBeVisible(); + await expect.poll(() => nav.evaluate((el) => (el as HTMLElement).style.transform)).toBe("translateY(300px)"); + await page.evaluate(() => window.dispatchEvent(new Event("touchstart"))); + await expect.poll(() => nav.evaluate((el) => (el as HTMLElement).style.transform)).toBe(""); +}); + +test("the bridge ends by itself after a second, and never starts without typing", async ({ page }) => { + await page.goto("/mehr"); + const nav = page.getByRole("navigation", { name: "Navigation" }); + await moveViewport(page, 300); // ohne Tastatur: nichts tun + await page.waitForTimeout(100); + expect(await nav.evaluate((el) => (el as HTMLElement).style.transform)).toBe(""); + await page.locator("#kid-name").focus(); + await page.locator("#kid-name").blur(); + await expect.poll(() => nav.evaluate((el) => (el as HTMLElement).style.transform)).toBe("translateY(300px)"); + await expect.poll(() => nav.evaluate((el) => (el as HTMLElement).style.transform), { timeout: 3000 }).toBe(""); +}); diff --git a/lib/use-keyboard-nav.ts b/lib/use-keyboard-nav.ts index f478eba..d9b3514 100644 --- a/lib/use-keyboard-nav.ts +++ b/lib/use-keyboard-nav.ts @@ -5,8 +5,28 @@ import { useEffect, useRef, useState } from "react"; // iOS (Web-App vom Home-Bildschirm): Nach dem Schließen der Tastatur bleibt eine // feste Leiste oft dort stehen, wo die Tastatur endete — mitten im Bild (Kai, // 7.11.2026). Deshalb: Während getippt wird, ist die Leiste weg; danach richtet sie -// sich am sichtbaren Bereich (visualViewport) aus statt am Layout, das iOS zu kurz -// stehen lässt, und ein Scroll auf der Stelle stößt das Neuvermessen an. +// sich kurz am sichtbaren Bereich (visualViewport) aus. +// +// Nur kurz (26.11.32): Bis 26.11.31 hing die Korrektur an jedem Scroll- und +// Größenereignis des sichtbaren Bereichs. In Safari fährt beim Scrollen die +// Adressleiste ein und aus, iOS meldet das verzögert — die Leiste rutschte mit +// (Kai, 7.11.2026). Jetzt gilt: Beim Scrollen fasst Lunch die Leiste nie an. +// Korrigiert wird nur im Fenster nach dem Schließen der Tastatur, und die erste +// Berührung oder der erste Scroll danach nimmt die Korrektur zurück. + +/** Wie lange nach dem Schließen der Tastatur nachgemessen wird. */ +export const SETTLE_MS = 1000; + +/** Web-App vom Home-Bildschirm? Nur dort trat der Fehler auf; in Safari ist eine Lücke die Adressleiste. */ +export const isStandalone = () => + window.matchMedia?.("(display-mode: standalone)").matches || (navigator as Navigator & { standalone?: boolean }).standalone === true; + +/** Abstand zwischen Unterkante des sichtbaren Bereichs und der des Layouts; 0, wenn nichts zu tun ist. */ +export function keyboardGap(vv: { offsetTop: number; height: number; scale: number }, layoutHeight: number): number { + if (vv.scale > 1.01) return 0; // gezoomt: nicht eingreifen + const gap = Math.round(vv.offsetTop + vv.height - layoutHeight); + return gap > 40 && gap < 800 ? gap : 0; // kleine Lücken sind Adressleiste oder Gummiband, keine Tastatur +} const EDITABLE = 'input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="range"]):not([type="file"]), textarea, select, [contenteditable=""], [contenteditable="true"]'; @@ -25,38 +45,61 @@ export function useKeyboardSafeNav() { useEffect(() => { const vv = window.visualViewport; - // Abstand zwischen Unterkante des sichtbaren Bereichs und der des Layouts. + let until = 0; // Ende des Fensters nach dem Schließen der Tastatur + const clear = () => { + until = 0; + if (ref.current) ref.current.style.transform = ""; + }; const pin = () => { const el = ref.current; if (!el || !vv) return; - const gap = vv.scale > 1.01 ? 0 : Math.round(vv.offsetTop + vv.height - document.documentElement.clientHeight); - el.style.transform = gap > 0 && gap < 800 ? `translateY(${gap}px)` : ""; + if (Date.now() > until || !isStandalone()) return clear(); + const gap = keyboardGap(vv, document.documentElement.clientHeight); + el.style.transform = gap ? `translateY(${gap}px)` : ""; }; const onFocusIn = (e: FocusEvent) => { - if (isEditable(e.target as Element)) setTyping(true); + if (isEditable(e.target as Element)) { + clear(); + setTyping(true); + } }; const onFocusOut = () => { // Erst prüfen, wenn der Fokus angekommen ist (Feld → Feld bleibt „tippen“). setTimeout(() => { if (isEditable(document.activeElement)) return; setTyping(false); - window.scrollTo(window.scrollX, window.scrollY); + window.scrollTo(window.scrollX, window.scrollY); // stößt das Neuvermessen an + until = Date.now() + SETTLE_MS; requestAnimationFrame(pin); setTimeout(pin, 300); // nach der Animation der Tastatur noch einmal + setTimeout(() => { + if (!until) return; + clear(); + // Steht die Leiste ohne Korrektur noch falsch, iOS noch einmal neu messen lassen. + if (vv && isStandalone() && keyboardGap(vv, document.documentElement.clientHeight)) { + window.scrollTo(window.scrollX, window.scrollY + 1); + window.scrollTo(window.scrollX, window.scrollY - 1); + } + }, SETTLE_MS + 50); }, 50); }; + // Sobald die Person wieder berührt (jeder Scroll am Handy beginnt so) oder am Rad + // dreht, gilt die Lage, die iOS selbst rechnet. Kein „scroll“: Den lösen auch das + // scrollTo oben und iOS beim Schließen der Tastatur aus. + const onUser = () => until && clear(); document.addEventListener("focusin", onFocusIn); document.addEventListener("focusout", onFocusOut); vv?.addEventListener("resize", pin); - vv?.addEventListener("scroll", pin); - window.addEventListener("orientationchange", pin); - pin(); + window.addEventListener("touchstart", onUser, { passive: true }); + window.addEventListener("wheel", onUser, { passive: true }); + window.addEventListener("orientationchange", clear); return () => { document.removeEventListener("focusin", onFocusIn); document.removeEventListener("focusout", onFocusOut); vv?.removeEventListener("resize", pin); - vv?.removeEventListener("scroll", pin); - window.removeEventListener("orientationchange", pin); + window.removeEventListener("touchstart", onUser); + window.removeEventListener("wheel", onUser); + window.removeEventListener("orientationchange", clear); }; }, []); diff --git a/olares/Chart.yaml b/olares/Chart.yaml index aa3f90a..c57f652 100644 --- a/olares/Chart.yaml +++ b/olares/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: lunch description: Was gibt's? — die Familie entscheidet gemeinsam, was es gibt; aus dem Plan entsteht die Einkaufsliste type: application -version: 26.11.31 # YY.M. wie im AImighty-Markt — bei jeder Chart-Änderung erhöhen -appVersion: "26.11.31" # MUSS gleich version sein: der Linter prüft es, und der Image-Tag hängt daran +version: 26.11.32 # YY.M. wie im AImighty-Markt — bei jeder Chart-Änderung erhöhen +appVersion: "26.11.32" # MUSS gleich version sein: der Linter prüft es, und der Image-Tag hängt daran diff --git a/olares/OlaresManifest.yaml b/olares/OlaresManifest.yaml index 6ab6d9a..c281817 100644 --- a/olares/OlaresManifest.yaml +++ b/olares/OlaresManifest.yaml @@ -21,7 +21,7 @@ metadata: title: What's cooking? description: The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box. icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png - version: 26.11.31 + version: 26.11.32 categories: - Applications @@ -61,7 +61,7 @@ permission: appData: true spec: - versionName: '26.11.31' + versionName: '26.11.32' featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png promoteImage: diff --git a/olares/markt/26.11.32.md b/olares/markt/26.11.32.md new file mode 100644 index 0000000..d24e71a --- /dev/null +++ b/olares/markt/26.11.32.md @@ -0,0 +1,5 @@ +# The bottom bar stays down +v26.11.32: The bottom bar no longer slides up while scrolling. The fix for the keyboard (26.11.18) moved the bar on every scroll as the address bar came and went; now Lunch leaves the bar alone while scrolling. Only in the home-screen app, and only for a second after the keyboard closes, it closes a gap the keyboard left behind — the first touch ends that. + +## Deutsch +v26.11.32: Die Leiste unten rutscht beim Scrollen nicht mehr mit nach oben. Die Korrektur für die Tastatur (26.11.18) schob die Leiste bei jedem Scrollen nach, während die Adressleiste ein- und ausfuhr; jetzt lässt Lunch die Leiste beim Scrollen in Ruhe. Nur in der Web-App vom Home-Bildschirm und nur eine Sekunde nach dem Schließen der Tastatur schließt sie eine Lücke, die die Tastatur hinterlassen hat — die erste Berührung beendet das. diff --git a/playwright.config.ts b/playwright.config.ts index 5819e00..1e68b3d 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -75,10 +75,16 @@ export default defineConfig({ dependencies: ["kueche"], use: { ...iphone, storageState: "e2e/.auth/kai.json" }, }, + { + name: "leiste", + testMatch: /leiste\.spec\.ts/, + dependencies: ["pwa"], + use: { ...iphone, storageState: "e2e/.auth/kai.json" }, + }, { name: "iphone-hell", testMatch: /rundgang\.spec\.ts/, - dependencies: ["pwa"], + dependencies: ["leiste"], use: { ...iphone, colorScheme: "light", storageState: "e2e/.auth/kai.json" }, }, { diff --git a/tests/keyboard-gap.test.ts b/tests/keyboard-gap.test.ts new file mode 100644 index 0000000..8a45231 --- /dev/null +++ b/tests/keyboard-gap.test.ts @@ -0,0 +1,20 @@ +import { describe, expect, it } from "vitest"; +import { keyboardGap } from "@/lib/use-keyboard-nav"; + +// Wann die untere Leiste nach dem Tippen nachgeschoben wird (26.11.32): nur bei einer +// Lücke, wie sie eine eben geschlossene Tastatur hinterlässt — nie für Adressleiste, +// Gummiband oder Zoom. +describe("keyboard gap", () => { + const vv = (height: number, offsetTop = 0, scale = 1) => ({ height, offsetTop, scale }); + it("is the stale space a closed keyboard leaves behind", () => { + expect(keyboardGap(vv(852), 520)).toBe(332); + }); + it("ignores small gaps from the address bar or a bounce, and negative ones", () => { + expect(keyboardGap(vv(852), 812)).toBe(0); + expect(keyboardGap(vv(780, -30), 812)).toBe(0); + }); + it("leaves a zoomed page alone and refuses absurd values", () => { + expect(keyboardGap(vv(852, 0, 2), 520)).toBe(0); + expect(keyboardGap(vv(5000), 520)).toBe(0); + }); +}); -- 2.54.0