fix(android): keep the app clear of the status and navigation bars

targetSdk 36 and MainActivity's enableEdgeToEdge() draw the webview under
both system bars. The React 1.x shell padded all four safe-area insets; the
SvelteKit rewrite kept only <main>'s bottom one, so the top bar of every 2.x
app has sat under the clock, which docs/android-support.md says cannot happen.

- styles/theme.css gains pt-safe, pb-safe, pl-safe, pr-safe and p-safe-or-4
  (env(safe-area-inset-*), named after the tailwindcss-safe-area classes).
  The shell root carries pt-safe pl-safe pr-safe, <main> pb-safe, the drawer
  pt-safe pb-safe pl-safe, and /welcome and the /error pages, which have no
  shell, pad themselves.
- The consent gate and the human check use p-safe-or-4 and centre their card
  with m-auto instead of items-center: on a short phone a card taller than
  the screen lost its top, unreachable (measured at 360x520: the 620px
  consent card now scrolls from its top edge).
- Back-to-top and the toasts add the bottom inset; the never-expiring Android
  update toast sat on the gesture bar.
- The status-bar icons follow the SYSTEM theme (enableEdgeToEdge() uses
  SystemBarStyle.auto), but the app defaults to dark, so a phone in light
  mode showed dark icons on a dark page. In the Android app the layout now
  puts a status-bar-strip behind them, keyed on prefers-color-scheme and
  never on the reader's theme. Its two colours are theme.css's --background
  tokens; mobile-layout.test.ts compares them and holds the shell padding.

env() reports these insets only from Android System WebView 136; an older
WebView reads 0 and keeps today's look. The Android docs now say so, and the
themes.xml comments, which still pointed at the React Layout and claimed
light icons, describe what enableEdgeToEdge() actually does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5.5 committed 2026-10-03 06:42:01 +07:00
1 parent 21d06a32fb
commit a22589a334
13 files changed
+183 -23

No files matched your search

+15
View File
@@ -229,6 +229,21 @@ scraping pipeline (`scripts/`) driven by GitHub Actions.
word) squeezed game names to nothing at 360px the same way - hide the
extras below `sm`. `src/lib/mobile-layout.test.ts` fails on a grid without
a base `grid-cols-N`.
- **The Android app draws edge-to-edge, and the UI pads for it with
`env(safe-area-inset-*)`.** targetSdk 36 and `enableEdgeToEdge()` put the
webview under the status bar and the navigation bar. The shell root carries
`pt-safe pl-safe pr-safe`, `<main>` `pb-safe`, the drawer `pt-safe pb-safe`
and full-screen overlays `p-safe-or-4` (utilities in `styles/theme.css`).
The React shell padded all four sides; the SvelteKit rewrite dropped three,
which is how the top bar of every 2.x app sat under the clock. The
status-bar ICONS follow the SYSTEM theme (`SystemBarStyle.auto`), not the one
chosen in Settings, and the app defaults to dark - so the layout puts a
`status-bar-strip` behind them, in the Android app only, keyed on
`prefers-color-scheme` and never on `.dark`. The WebView reports the insets
only from Android System WebView 136; an older one reads 0 and the top bar
is under the clock again (the cure is a WebView update, or a native inset
listener in `MainActivity`). `mobile-layout.test.ts` holds the shell and the
strip's two colours.
- **Every chart colour must be one zrender can parse, which is stricter than
what a canvas paints.** zrender splits `hsl()` on commas: space-separated
`hsl(38 94% 60%)` paints, but every hover state derived from it comes back
+3
View File
@@ -40,6 +40,9 @@ install gate. (Set in [`gen/android/app/build.gradle.kts`](../web/src-tauri/gen/
3. **Edge-to-edge & safe areas.** We compile against `targetSdk 36` (Android 16),
which forces edge-to-edge layout; the UI uses `env(safe-area-inset-*)` to dodge
the status / gesture-nav bars. These behave most reliably on Android 11+.
The WebView only reports those insets from **Android System WebView 136**; on
an older one the top bar sits under the status bar, and updating "Android
System WebView" from the Play Store fixes it.
4. **Tested surface.** We only test from Android 11 upward (see below); we don't
want to ship a floor we can't smoke-test.
+3
View File
@@ -37,6 +37,9 @@ cách bypass trong app — nên ngưỡng phiên bản cũng chính là cổng c
3. **Edge-to-edge & safe area.** Ta compile với `targetSdk 36` (Android 16), buộc
layout edge-to-edge; UI dùng `env(safe-area-inset-*)` để né thanh status /
gesture-nav. Những hành vi này ổn định nhất trên Android 11+.
WebView chỉ báo các inset này từ **Android System WebView 136**; với bản cũ
hơn, thanh trên cùng sẽ nằm dưới thanh trạng thái, và cập nhật "Android
System WebView" qua Play Store là khắc phục được.
4. **Phạm vi test.** Ta chỉ test từ Android 11 trở lên (xem dưới); không muốn ship
một ngưỡng không thể smoke-test.
@@ -1,8 +1,8 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.f2p_tracker" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Mirror values/themes.xml: transparent system bars + light icons for
the dark-by-default web UI under edge-to-edge (targetSdk 36). -->
<!-- Mirror values/themes.xml, which explains why enableEdgeToEdge()
overrides the icon colours and how the web UI handles the insets. -->
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">false</item>
@@ -1,11 +1,14 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.f2p_tracker" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Edge-to-edge (targetSdk 36): keep the system bars transparent and use
light icons to match the app's dark-by-default chrome. The web UI
paints its own background behind them via the safe-area insets in
Layout. (If the user picks the light in-app theme the status-bar
icons sit on a light strip — a minor, accepted trade-off.) -->
<!-- Edge-to-edge (targetSdk 36): transparent system bars. These items are
only the starting point: MainActivity calls enableEdgeToEdge(), whose
SystemBarStyle.auto sets the bar and icon colours from the SYSTEM dark
mode at runtime, so the windowLight* values below are overridden. The
web UI keeps its content out of both bars with the safe-area insets
(web/src/routes/+layout.svelte, utilities in web/src/styles/theme.css)
and paints a strip behind the status bar that follows the system
theme as well, so the icons read whichever theme the app is in. -->
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">false</item>
+4 -1
View File
@@ -21,15 +21,18 @@
});
</script>
<!-- bottom-4/right-4 plus the safe-area insets, so in the Android app the
button clears the navigation bar (see the utilities in styles/theme.css). -->
<button
type="button"
aria-label={i18n.t("common.backToTop")}
onclick={() => scroller?.scrollTo({ top: 0, behavior: "smooth" })}
class={cn(
"fixed bottom-4 right-4 z-20 grid size-10 place-items-center rounded-full border",
"fixed z-20 grid size-10 place-items-center rounded-full border",
"bg-card text-muted-foreground shadow-lg transition-all hover:text-foreground",
visible ? "opacity-100" : "pointer-events-none translate-y-2 opacity-0",
)}
style="bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); right: calc(1rem + env(safe-area-inset-right, 0px))"
>
<ArrowUp class="size-4" />
</button>
+8 -4
View File
@@ -104,11 +104,15 @@
}
</script>
<!-- Both cards below centre with m-auto, not items-center: auto margins centre
a card that fits and collapse for one that does not, so on a short phone
the card scrolls from its top instead of losing it above the screen.
p-safe-or-4 keeps it clear of the Android system bars. -->
{#if !open}
<!-- nothing: the page underneath is already rendered -->
{:else if declined}
<div class="fixed inset-0 z-[60] flex items-center justify-center overflow-auto bg-background/95 p-4 backdrop-blur-sm">
<div class="w-full max-w-md rounded-lg border border-warning/40 bg-warning/5 p-8 text-center">
<div class="fixed inset-0 z-[60] flex overflow-auto bg-background/95 p-safe-or-4 backdrop-blur-sm">
<div class="m-auto w-full max-w-md rounded-lg border border-warning/40 bg-warning/5 p-8 text-center">
<ShieldCheck class="mx-auto mb-4 size-10 text-warning" />
<h1 class="mb-2 text-xl font-semibold">{t("consent.declinedTitle")}</h1>
<p class="text-sm text-muted-foreground">{t("consent.declinedBody")}</p>
@@ -118,8 +122,8 @@
</div>
</div>
{:else}
<div class="fixed inset-0 z-[60] flex items-center justify-center overflow-auto bg-background/95 p-4 backdrop-blur-sm">
<div class="w-full max-w-lg rounded-xl border bg-card p-6 shadow-xl sm:p-8">
<div class="fixed inset-0 z-[60] flex overflow-auto bg-background/95 p-safe-or-4 backdrop-blur-sm">
<div class="m-auto w-full max-w-lg rounded-xl border bg-card p-6 shadow-xl sm:p-8">
<div class="mb-5 flex items-start gap-3">
<span class="grid size-10 shrink-0 place-items-center rounded-lg bg-primary/15 text-primary">
{#if reviewing}
+3 -1
View File
@@ -79,7 +79,9 @@
<meta name="robots" content="noindex" />
</svelte:head>
<div class={cn("flex items-center justify-center p-4", inline ? "min-h-[60vh]" : "min-h-dvh")}>
<!-- Standalone (the /error pages) it has no shell around it, so it clears the
Android system bars itself; inline it sits inside the padded shell. -->
<div class={cn("flex items-center justify-center", inline ? "min-h-[60vh] p-4" : "min-h-dvh p-safe-or-4")}>
<div class="w-full max-w-md text-center">
<span
class={cn(
+4 -2
View File
@@ -158,13 +158,15 @@
</script>
{#if open}
<div class="fixed inset-0 z-[60] flex items-center justify-center overflow-auto bg-background/95 p-4 backdrop-blur-sm">
<!-- m-auto rather than items-center, as in ConsentGate.svelte: a card
taller than the screen scrolls from its top instead of losing it. -->
<div class="fixed inset-0 z-[60] flex overflow-auto bg-background/95 p-safe-or-4 backdrop-blur-sm">
<div
role="dialog"
aria-modal="true"
aria-labelledby="human-check-title"
aria-describedby="human-check-intro"
class="w-full max-w-md rounded-xl border bg-card p-6 shadow-xl sm:p-8"
class="m-auto w-full max-w-md rounded-xl border bg-card p-6 shadow-xl sm:p-8"
>
<div class="mb-5 flex items-start gap-3">
<span class="grid size-10 shrink-0 place-items-center rounded-lg bg-primary/15 text-primary">
+53 -2
View File
@@ -4,8 +4,8 @@ import { describe, expect, it } from "vitest";
import { withoutBlockComments } from "./testing/source";
/**
* Layout rules for a phone-width screen, found broken on a 360px Android
* phone in 4.1.0; CLAUDE.md, "Frontend gotchas", has the story.
* Layout rules for a phone-width screen. Both were found broken on a 360px
* Android phone in 4.1.0; CLAUDE.md, "Frontend gotchas", has the story.
*/
const SRC = join(__dirname, "..");
@@ -58,3 +58,54 @@ describe("layout grids declare their base column count", () => {
expect(grids.filter((g) => !/\sgrid-cols-\d+(\s|$)/.test(g))).toEqual([]);
});
});
describe("the app keeps clear of the Android system bars", () => {
/**
* targetSdk 36 draws the webview under the status bar and the navigation
* bar. The React shell padded all four safe-area insets; the SvelteKit
* rewrite kept only the bottom one, and the top bar of every 2.x app sat
* under the clock. docs/android-support.md promises this.
*/
const layout = readFileSync(join(SRC, "routes", "+layout.svelte"), "utf-8");
const css = readFileSync(join(SRC, "styles", "theme.css"), "utf-8");
const lists = classLists(withoutBlockComments(layout));
const find = (marker: string) => lists.find((tokens) => tokens.includes(marker)) ?? [];
it("pads the shell, the page and the drawer", () => {
expect(find("h-dvh")).toEqual(expect.arrayContaining(["pt-safe", "pl-safe", "pr-safe"]));
expect(find("scrollbar-page")).toEqual(expect.arrayContaining(["pb-safe"]));
expect(find("w-72")).toEqual(expect.arrayContaining(["pt-safe", "pb-safe"]));
});
it("defines the padding utilities from env(safe-area-inset-*)", () => {
for (const side of ["top", "bottom", "left", "right"]) {
const name = `p${side[0]}-safe`;
expect(css).toMatch(
new RegExp(`@utility ${name} \\{\\s*padding-${side}: env\\(safe-area-inset-${side}, 0px\\);`),
);
}
});
it("puts the status-bar strip on the page", () => {
expect(withoutBlockComments(layout)).toMatch(/<div class="status-bar-strip" aria-hidden="true"><\/div>/);
});
it("paints the strip in the SYSTEM theme's background, light and dark", () => {
// The status-bar icons follow the system theme (enableEdgeToEdge() uses
// SystemBarStyle.auto), so the strip uses the two --background tokens
// keyed on prefers-color-scheme, never the reader's choice in Settings.
const token = (selector: string) =>
css.match(new RegExp(`(?:^|\\n)${selector} \\{[^}]*?--background: ([^;]+);`))?.[1];
const light = token(":root");
const dark = token("\\.dark");
expect(light).toBeTruthy();
expect(dark).toBeTruthy();
const strip = css.slice(css.indexOf("@utility status-bar-strip {"));
const block = strip.slice(0, strip.indexOf("\n}\n") + 2);
expect(block).toContain(`background-color: hsl(${light});`);
expect(block).toMatch(
new RegExp(`@media \\(prefers-color-scheme: dark\\) \\{\\s*background-color: hsl\\(${dark}\\);`),
);
});
});
+28 -5
View File
@@ -43,6 +43,7 @@
let menuOpen = $state(false);
// Set on mount: isTauri() reads a runtime global the prerenderer does not have.
let tauriDesktop = $state(false);
let androidApp = $state(false);
// Module-level would leak across HMR reloads in dev; per-instance is enough
// because the layout mounts once.
let updateChecked = false;
@@ -110,6 +111,7 @@
// Desktop only: the updater plugin is not compiled for Android, which
// checks for a newer APK below instead.
tauriDesktop = isTauri() && !isAndroid();
androidApp = isTauri() && isAndroid();
// Android has no native Tauri updater (the plugin is desktop-only), so the
// APK checks GitHub Releases itself, once per session. Best-effort: a
@@ -211,7 +213,11 @@
{:else}
<a href="#main" class="skip-link">{i18n.t("common.skipToContent")}</a>
<div class="flex h-dvh overflow-hidden">
<!-- The safe-area padding keeps the shell out from under the Android status
bar (and a landscape cutout); <main> takes the bottom inset itself, so
the page scrolls behind the navigation bar but its last line clears it.
See the safe-area utilities in styles/theme.css. -->
<div class="flex h-dvh overflow-hidden pt-safe pl-safe pr-safe">
<aside class="hidden w-60 shrink-0 border-r bg-card/40 lg:block">
<Sidebar />
</aside>
@@ -223,7 +229,7 @@
<Dialog.Portal>
<Dialog.Overlay class="fixed inset-0 z-40 bg-black/60 lg:hidden" />
<Dialog.Content
class="fixed inset-y-0 left-0 z-50 w-72 border-r bg-card shadow-xl outline-none lg:hidden"
class="fixed inset-y-0 left-0 z-50 w-72 border-r bg-card pt-safe pb-safe pl-safe shadow-xl outline-none lg:hidden"
>
<Dialog.Title class="sr-only">{i18n.t("nav.menu")}</Dialog.Title>
<Sidebar onNavigate={() => (menuOpen = false)} />
@@ -236,8 +242,7 @@
<main
bind:this={main}
id="main"
class="flex-1 overflow-y-auto scrollbar-slim scrollbar-page"
style="padding-bottom: env(safe-area-inset-bottom)"
class="flex-1 overflow-y-auto pb-safe scrollbar-slim scrollbar-page"
>
<div class="container py-6">
{#if unmatched}
@@ -264,9 +269,27 @@
The same kind of overlay, never open at the same time as the one above. -->
<HumanCheck />
<!-- Android app only: what shows through the transparent status bar, above
every overlay, so the clock stays readable on whatever is open. Why it
follows the system theme is in styles/theme.css (status-bar-strip). -->
{#if androidApp}<div class="status-bar-strip" aria-hidden="true"></div>{/if}
<!-- theme, not a hardcoded "dark": main.tsx pinned the Toaster to dark while
the rest of the app had a working light mode, so every toast was a dark
card on a white page. -->
<Toaster theme={theme.resolved} position="bottom-right" richColors closeButton />
<!-- The offsets add the bottom inset: in the Android app the never-expiring
update toast otherwise sat on the gesture bar. svelte-sonner's defaults are
32px, and 16px below 600px. -->
<Toaster
theme={theme.resolved}
position="bottom-right"
richColors
closeButton
offset={{
bottom: "calc(32px + env(safe-area-inset-bottom, 0px))",
right: "calc(32px + env(safe-area-inset-right, 0px))",
}}
mobileOffset={{ bottom: "calc(16px + env(safe-area-inset-bottom, 0px))" }}
/>
<PwaIndicator />
{#if tauriDesktop}<DesktopUpdateDialog />{/if}
+2 -1
View File
@@ -42,7 +42,8 @@
<Seo title={t("welcome.title")} description={t("welcome.heading")} />
<div class="min-h-dvh bg-background">
<!-- Chrome-less, so it clears the Android system bars itself (styles/theme.css). -->
<div class="min-h-dvh bg-background pt-safe pb-safe">
<div class="mx-auto flex max-w-3xl flex-col gap-10 px-4 py-12 sm:py-16">
<header class="space-y-4">
<span class="grid size-12 place-items-center rounded-xl bg-primary text-primary-foreground shadow-sm">
+50
View File
@@ -179,6 +179,56 @@
font-feature-settings: "tnum" 1;
}
/* Safe areas: the Android app draws edge-to-edge.
targetSdk 36 enforces it and MainActivity asks for it (enableEdgeToEdge()),
so the webview runs under the status bar and the navigation bar. These keep
content out of both. env() needs viewport-fit=cover (app.html) and reads 0
on the web, in the desktop apps and in an Android System WebView older than
136, so every one of them is a no-op there. Named after the
tailwindcss-safe-area plugin's classes. The React shell padded all four
insets; the SvelteKit rewrite kept only the bottom one, which is how the top
bar of the 2.x apps ended up under the clock. src/lib/mobile-layout.test.ts
holds the shell to them. */
@utility pt-safe {
padding-top: env(safe-area-inset-top, 0px);
}
@utility pb-safe {
padding-bottom: env(safe-area-inset-bottom, 0px);
}
@utility pl-safe {
padding-left: env(safe-area-inset-left, 0px);
}
@utility pr-safe {
padding-right: env(safe-area-inset-right, 0px);
}
/* p-4 that also clears the system bars: for full-screen overlays. */
@utility p-safe-or-4 {
padding: max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px))
max(1rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
}
/* What sits behind the Android status bar.
Its icons follow the SYSTEM theme, not the one chosen in Settings:
enableEdgeToEdge() uses SystemBarStyle.auto. The app defaults to dark, so on
a phone in light mode the icons were dark on a dark page. This strip follows
the system theme too - the two colours are --background from :root and from
.dark above (mobile-layout.test.ts compares them) - so the clock always
reads. The layout renders it only in the Android app; its height is the
inset, so it is nothing wherever env() reads 0. */
@utility status-bar-strip {
position: fixed;
inset: 0 0 auto;
z-index: 70;
height: env(safe-area-inset-top, 0px);
pointer-events: none;
background-color: hsl(40 30% 98%);
@media (prefers-color-scheme: dark) {
background-color: hsl(30 14% 7%);
}
}
@layer base {
/* v4 defaults borders to currentColor instead of gray-200; this keeps every
border on the token. */