Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
docs: record the safe-area inset contract for Android
Elian Doran60c5a82a319b
diff --git a/.claude/skills/building-client-ui/SKILL.md b/.claude/skills/building-client-ui/SKILL.mdindex c17706151b..603a03a4fb 100644--- a/.claude/skills/building-client-ui/SKILL.md+++ b/.claude/skills/building-client-ui/SKILL.md@@ -144,7 +144,7 @@ Rules for `OverlayControlButton`, which cover every case seen so far:- **`icon` is a boxicons name** (`bx-plus-circle`), **`text` is what stands inside**. Given both, the component renders the mark as a child span itself — never put a `bx` class on a button that also wears words, since the icon font would fall on the words too.- **`active`/`disabled` are props**, not classes concatenated into `className`.- **Pass `overCanvas`** when the group stands over something that is dragged (a map), so a press on a button is not taken for the start of a drag.-- **Where the group stands is the group's own**, via `placement` (`top`/`bottom` × `start`/`center`/`end`): it pins itself over the nearest positioned ancestor, and its tooltips open away from that edge. **Never write `position: absolute` plus insets at the call site.** What the caller does hand over, in that widget's CSS, is the room to keep from the edges (`--overlay-group-inset`, or the per-edge `--overlay-group-inset-top`/`-bottom`/`-start`/`-end` where one edge differs — a fullscreen map clearing a notch) and the `z-index`. `titlePosition` overrides the tooltip direction and is rarely right; only add a class to a *button* if a rule actually uses it.+- **Where the group stands is the group's own**, via `placement` (`top`/`bottom` × `start`/`center`/`end`): it pins itself over the nearest positioned ancestor, and its tooltips open away from that edge. **Never write `position: absolute` plus insets at the call site.** What the caller does hand over, in that widget's CSS, is the room to keep from the edges (`--overlay-group-inset`, or the per-edge `--overlay-group-inset-top`/`-bottom`/`-start`/`-end` where one edge differs — a fullscreen map clearing a notch, which spells that inset `var(--safe-area-inset-top, env(safe-area-inset-top))`, never a bare `env()`, since Android leaves `env()` at `0`) and the `z-index`. `titlePosition` overrides the tooltip direction and is rarely right; only add a class to a *button* if a rule actually uses it.- **Overlay controls exist in every layout.** Never gate a group on `isExperimentalFeatureEnabled("new-layout")`, and when an action moves onto a group, **delete its twin in `FloatingButtonsDefinitions.tsx`** rather than keeping both: that bar only renders in the old layout (`desktop_layout.tsx` mounts it with `!isNewLayout`), so a layout-gated group plus a floating fallback means two implementations of one button that drift. Keep the underlying app commands (e.g. `relationMapResetZoomIn`) even once the group is their only caller — note scripts can fire them via `api.triggerCommand`.- Reuse shared labels from the `common` translation namespace (e.g. `common.fullscreen`) rather than adding a per-widget copy of a string the app already has.diff --git a/.claude/skills/developing-capacitor-mobile/SKILL.md b/.claude/skills/developing-capacitor-mobile/SKILL.mdindex 1e990926ae..1233cfc4b6 100644--- a/.claude/skills/developing-capacitor-mobile/SKILL.md+++ b/.claude/skills/developing-capacitor-mobile/SKILL.md@@ -54,6 +54,38 @@ A fetch from the app origin to a sync server is cross-origin, so CORS and cookie- **iOS `ViewController`**: the layout is `body { position: fixed; height: 100vh }` with an inner scrolling container, so WKWebView's reflexive scroll-to-focused-element would drag the toolbar off-screen; the controller pins the outer scroll offset while the keyboard animates and samples the keyboard's top edge every frame into the `--tn-keyboard-gap` CSS variable so the editor toolbar follows an interactive swipe-dismiss. `Keyboard.resize: "native"` in the config is part of the same contract. Change the keyboard/toolbar CSS on the client and this controller together.- `limitsNavigationsToAppBoundDomains: true` on iOS.+## Safe-area insets: never write a bare `env(safe-area-inset-*)`++Android's WebView does not populate `env(safe-area-inset-*)` — it resolves to `0`, silently, on every+Android version. `MainActivity.forwardInsetsToWebView()` works around it by setting+`--safe-area-inset-top`/`-bottom`/`-left`/`-right` (plus `--keyboard-height`) on+`document.documentElement` from the real `WindowInsetsCompat` values, in CSS pixels, on every inset+change.++**So client CSS must read the variable with `env()` only as the fallback:**++```css+padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom));+```++The fallback is what keeps iOS and desktop browsers right, where the variable is never injected and+`env()` is authoritative. Get the two axes matching — `var(--safe-area-inset-left, env(safe-area-inset-left))`,+never a `-left` var falling back to `env(…-right)`.++- **Bare `env()` is a bug on Android, not a style nit.** It had gone unnoticed at 27 call sites+ (fixed in `a8f4e9f405`), including `--mobile-bottom-offset`, which puts the mobile launcher bar+ under the gesture pill.+- **The one deliberate exception** is the `body.ios` `--mobile-bottom-offset` override in+ `apps/client/src/stylesheets/style.css` — platform-scoped to where `env()` is the real source.+- **`body.desktop` rules are in scope too.** An Android tablet WebView has no `Mobi` in its UA, so+ `isMobile()` is false and `index.ts` picks the desktop layout for it.+- **`--keyboard-height` is injected but read by nothing.** `MainActivity` resizes the WebView through+ `bottomMargin` instead, so the CSS viewport shrinks on its own. iOS drives `--tn-keyboard-gap` from+ `ViewController` for a different purpose; the two are not a pair.++Audit with `grep -rn "env(safe-area" --include=*.css apps/client/src apps/standalone/src` — every hit+should be wrapped in a matching `var()`.+## Client-side gating- `isMobileApp()` (`apps/client/src/services/utils.ts`) — `window.Capacitor?.isNativePlatform?.()`: true only inside the native wrapper. Distinct from `isMobile()`, which is the *layout* choice and is also true for a phone browser. Use the former for "there is a native shell" behaviour (e.g. setup flow), the latter for responsive UI. `window.Capacitor` is typed in `apps/client/src/types.d.ts`.diff --git a/CLAUDE.md b/CLAUDE.mdindex b452670abb..b4940aef1c 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -117,6 +117,7 @@ Shared components live in `apps/client/src/widgets/react/` — **always** reuse- **Per-component CSS files**: each component should have a matching `.css` file (e.g. `my_dialog.tsx` → `my_dialog.css`), imported at the top of the component file.- **CSS nesting for scoping**: since CSS modules are not available, scope styles using a root class and native CSS nesting. For example, a dialog with `className="my-dialog"` should have its styles nested under `.modal.my-dialog { … }`.- **Reuse existing components** instead of building custom markup — prefer `FormTextBox`, `FormTextBoxWithUnit`, `FormSelect`, `Slider`, `Button`, etc. over hand-rolled `<input>`, `<select>`, or `<button>` elements.+- **Safe-area insets** always read `var(--safe-area-inset-top, env(safe-area-inset-top))` (and the `-bottom`/`-left`/`-right` twins), never a bare `env()`. Android's WebView leaves `env(safe-area-inset-*)` at `0`, so `apps/mobile`'s `MainActivity` injects the real values as those custom properties; the `env()` fallback covers iOS and desktop browsers, where nothing is injected. Details in the **`developing-capacitor-mobile` skill**.### API Architecture