From 3c0d6560f1d1da8f38f83392cebb471b860f510d Mon Sep 17 00:00:00 2001 From: Elijah Date: Thu, 22 Oct 2026 10:11:55 -0700 Subject: [PATCH] Fix live swipe paging and retain tilt preference on iOS Replace the damped single-screen fade with live mobile panels on a shared composited rail, preserving per-tab scrolling and pausing offscreen physics. Center macro text and separate the saved tilt switch from session motion permission, resuming permission from a normal interaction. Validate live previews, interruption and multi-touch cancellation, relaunch, and permission races. --- README.md | 4 +- src/App.tsx | 262 ++++++++++------- src/PageActivity.ts | 4 + src/Settings.tsx | 19 +- src/main.tsx | 1 + src/mobile.css | 10 +- src/motion.css | 17 -- src/pager.css | 87 ++++++ src/useBubblePhysics.ts | 41 ++- src/useNavigation.ts | 315 ++++++++++++++------- src/useTilt.ts | 107 +++++-- tests/browser/mobile-layout.check.js | 2 +- tests/browser/native-interactions.check.js | 2 +- tests/browser/swipe-preview.check.js | 65 +++++ tests/tilt.test.js | 111 ++++++++ 15 files changed, 784 insertions(+), 263 deletions(-) create mode 100644 src/PageActivity.ts create mode 100644 src/pager.css create mode 100644 tests/browser/swipe-preview.check.js create mode 100644 tests/tilt.test.js diff --git a/README.md b/README.md index d887c23..2d1d9a7 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A single-user, self-hosted nutrition journal. PWA first, with a responsive deskt - Independently enabled calorie, protein, carbohydrate, fat, fiber, sugar and sodium goals. - Weight journal in lb or kg; internally stored in kg. Multiple weigh-ins are retained, with the latest measurement per day used in charts. - Dedicated Weight tab on desktop and mobile, with its own logging, graph and journal. Nutrition trends live under Library → Trends. Both support 7 / 30 / 90 / 365 day periods. Nutrition averages exclude empty and likely incomplete days: the initial cutoff is half the calorie target, adjustable under Settings → Nutrition averages (0 includes all logged days). Every nutrient uses the same qualifying days; faded bars and exports retain actual totals. This is a logging heuristic, so adjust it for your own routine. Saving preferences stores the cutoff in kcal independently of later goal changes. -- On phones, swipe left/right through Today → Library → Weight → Settings. Vertical scrolling, form controls, horizontal macro scrolling, and browser edge gestures remain independent. Pages and sheets animate with touch feedback; pull down from a sheet header to dismiss it. System Reduce Motion disables these transitions. +- On phones, swipe left/right through Today → Library → Weight → Settings. Neighboring screens are already rendered and move together under your finger; settling uses a composited slide with no fade-to-blank delay. Every tab retains its own scroll position. Vertical scrolling, form controls, horizontal macro scrolling, and browser edge gestures remain independent. The calorie simulation pauses on other tabs. Pull down from a sheet header to dismiss it. System Reduce Motion disables these transitions. - Markdown, CSV and JSON export with date range, nutrient and weight selections. Markdown is designed for LLM analysis. Data is downloaded locally, never submitted to an LLM. Save preferences to remember the export format, range preset and selections. - Password authentication, IndexedDB offline journal/outbox, a precached app shell, automatic foreground/reconnect sync, and explicit PWA update prompts. @@ -77,7 +77,7 @@ To restore a database backup: stop Calio, preserve the current data directory, r ### Bubble motion -Enable **Settings → Look & feel → Tilt calorie bubbles** to allow device orientation. On iPhone, Safari asks for motion/orientation permission from that gesture; the public site must use HTTPS. The preference is stored only on this device, and iOS may require enabling it again after reopening the app. Sensor readings are never transmitted. Portrait, landscape and upside-down positions are mapped to the screen's gravity direction. Devices without sensors, or with permission denied, retain downward gravity. +Enable **Settings → Look & feel → Tilt calorie bubbles** to allow device orientation. On iPhone, Safari asks for motion/orientation permission from that gesture; the public site must use HTTPS. The preference stays saved on this device across reopening, independently of browser permission. If iOS needs motion access again, Calio resumes it on your first normal interaction; Settings also provides **Allow motion** if needed. A denied request keeps the preference on and explains why tilt is unavailable. Sensor readings are never transmitted. Portrait, landscape and upside-down positions are mapped to the screen's gravity direction. Devices without sensors, or with permission denied, retain downward gravity. The circle uses a bounded Matter.js simulation: bubbles collide with each other and the circular wall, new calorie bubbles drop from the top at 30 per second (50% faster than the original pace), and removing calories removes the corresponding particles. Bubbles draw smaller than their collision boundaries, creating a small visible gap between them. A full hexagonal packing defines the 100% capacity. The numeric readout always sits below the circle, leaving every dot visible. The particle count caps at the daily goal; over-goal calories still show the exact excess and a red ring. With the calorie goal disabled, the display uses a fixed 2,500 kcal visual scale. Macro bars animate when totals change, and rows with one or two tracked macros are centered. Motion honors the device's reduced-motion preference. The physics animation sleeps when settled and pauses in hidden tabs. The graphic is an approximate visual; the numeric calorie total is authoritative. diff --git a/src/App.tsx b/src/App.tsx index 7983171..b240fb8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -76,7 +76,40 @@ import { Trends } from "./Trends"; import { Settings } from "./Settings"; import { Presence } from "./Presence"; -import { useNavigation } from "./useNavigation"; +import { useNavigation, type Page } from "./useNavigation"; +import { PageActivity } from "./PageActivity"; +import { useTiltResume } from "./useTilt"; +function PagePanel({ + name, + page, + mobile, + header, + children, +}: { + name: Page; + page: Page; + mobile: boolean; + header?: ReactNode; + children: ReactNode; +}) { + const active = page === name; + return ( +
+ + + {header} +
{children}
+
+
+
+ ); +} + type Editor = | { kind: "log"; meal: Meal; record?: JournalRecord } | { kind: "food"; record?: JournalRecord } @@ -800,11 +833,10 @@ export function App() { const status = useSyncStatus(); const [ready, setReady] = useState(false); const [fatal, setFatal] = useState(""); - const { - page, - navigate, - ref: pageRef, - } = useNavigation(ready && journal.unlocked); + const { page, navigate, mobile, viewportRef, railRef } = useNavigation( + ready && journal.unlocked, + ); + useTiltResume(ready && journal.unlocked); const [date, setDate] = useState(today()); const [editor, setEditor] = useState(null); const [toast, setToast] = useState(""); @@ -965,8 +997,42 @@ export function App() { {syncLabel} ); + const notices = ( + <> + {status.needsLogin && ( +
+ + Your session expired. Local logging is still available. + +
+ )} + {status.error && ( +
+ + Saved on this device. {status.error} + +
+ )} + {waiting && ( +
+ + A fresh version of Calio is ready. + +
+ )} + + ); + const panelHeader = ( +
+
+ + calio +
+ {syncControl} +
+ ); return ( -
+
-
+
Your journal / {nav.find((n) => n.key === page)?.label} @@ -1010,100 +1076,98 @@ export function App() {
n.key === page)?.label} > - {status.needsLogin && ( -
- - - Your session expired. Local logging is still available. - - -
- )} - {status.error && ( -
- - Saved on this device. {status.error} - -
- )} - {waiting && ( -
- - A fresh version of Calio is ready. - -
- )} - - setEditor({ kind: "log", meal })} - edit={(record) => - setEditor({ kind: "log", meal: record.data.meal, record }) - } - remove={setDeleting} - openLibrary={() => navigate("library")} - syncControl={syncControl} - /> - - - setEditor({ kind: "food" })} - newPlate={() => setEditor({ kind: "plate" })} - editFood={(record) => setEditor({ kind: "food", record })} - editPlate={(record) => setEditor({ kind: "plate", record })} - log={() => setEditor({ kind: "log", meal: suggestedMeal() })} - remove={setDeleting} - trends={ - - } - /> - - - setEditor({ kind: "weight" })} - editWeight={(record) => setEditor({ kind: "weight", record })} - remove={setDeleting} - /> - - - (journal.records, "settings")[0] - ?.updatedAt || "initial" - } - settings={settings} - records={journal.records} - pending={journal.outbox.length} - lastSync={journal.lastSync} - notify={notify} - install={ - installEvent - ? () => { - void installEvent.prompt(); - setInstallEvent(null); - } - : null - } - update={waiting ? () => void update() : null} - /> - +
+ + {notices} + setEditor({ kind: "log", meal })} + edit={(record) => + setEditor({ kind: "log", meal: record.data.meal, record }) + } + remove={setDeleting} + openLibrary={() => navigate("library")} + syncControl={syncControl} + /> + + + {notices} + setEditor({ kind: "food" })} + newPlate={() => setEditor({ kind: "plate" })} + editFood={(record) => setEditor({ kind: "food", record })} + editPlate={(record) => setEditor({ kind: "plate", record })} + log={() => setEditor({ kind: "log", meal: suggestedMeal() })} + remove={setDeleting} + trends={ + + } + /> + + + {notices} + setEditor({ kind: "weight" })} + editWeight={(record) => setEditor({ kind: "weight", record })} + remove={setDeleting} + /> + + + {notices} + (journal.records, "settings")[0] + ?.updatedAt || "initial" + } + settings={settings} + records={journal.records} + pending={journal.outbox.length} + lastSync={journal.lastSync} + notify={notify} + install={ + installEvent + ? () => { + void installEvent.prompt(); + setInstallEvent(null); + } + : null + } + update={waiting ? () => void update() : null} + /> + +

Look & feel

-
+