web: fit the iOS home screen app to the screen: black status bar style (iOS 26+ leaves the bottom unshown with black-translucent), the layout viewport's height, room above the home indicator and below the top fade, and no status line while the keyboard is up

This commit is contained in:
Pooya Parsa
2026-11-19 19:14:00 +00:00
parent 97d7945565
commit abdb84df66
4 changed files with 45 additions and 20 deletions

View File

@@ -242,12 +242,20 @@ deploying the page needs no kernel toolchain.
`#bar-errors`, `#status` (its CSS `color` turns red on an error) and
`#status-label`, `#panel` (class `open`), `#confirm`. Keep them working.
- Safe areas are the CSS variables `--st`, `--sr`, `--sb`, `--sl` (style.css). On iOS,
`--sb` is 0: the page keeps the top inset but takes the whole height below it, and the
status line moves its ends in by `--sc` (half the bottom inset) for the round corners.
`--sb` is three quarters of the bottom inset: the status line's background reaches the
bottom edge, its contents sit that far above it, and it moves its ends in by `--sc`
(half the bottom inset) for the round corners. While the on-screen keyboard is up
(`App.tsx` sets `kb` on the root when the visual viewport is well below the layout
viewport, so on iOS) both are 0 and the status line is hidden. In an iOS home screen
app `--st` is 24 px more than the top inset: iOS fades the page's top 20 px or so
there.
On macOS outside fullscreen, `main.tsx` sets `mac-window` on the root and `--sc` is
8 px, for the window's round bottom corners.
In a home screen app (standalone) `App.tsx` sizes `#app` to the screen's height,
rounded down, unless the keyboard is up, because iOS can report a shorter viewport there.
In a home screen app (standalone) `App.tsx` sizes `#app` to the layout viewport's height
unless the keyboard is up (the visual viewport can stay short after it closed). The
status bar style is `black`, not `black-translucent`: with that, iOS 26+ makes the
viewport shorter than the screen by the status bar and shows nothing below it (WebKit
bug 301108). iOS reads the style when the app is added to the home screen.
- An unknown or failed boot step must end in `ui.fail(...)`, so the
indicator turns red and the panel opens. The page must never stay blank.
`index.html` installs `error`/`unhandledrejection` handlers first and

View File

@@ -9,7 +9,8 @@
<!-- Added to the home screen, iOS opens the page without Safari's bars (it has no element full screen on iPhone). -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- Not black-translucent: iOS 26+ then gives the page a viewport short of the screen by the status bar and leaves a black band at the bottom (WebKit bug 301108). The page is black, so the status bar matches. -->
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="unkernel">
<meta name="color-scheme" content="dark">
<title>unkernel</title>

View File

@@ -82,6 +82,8 @@ function useViewport(app: RefObject<HTMLDivElement | null>) {
useEffect(() => {
const el = app.current!, bottom = trackBottom(document.getElementById("term")!), vv = visualViewport;
const apply = () => {
// The on-screen keyboard is up (not a pinch zoom, which also shrinks the visual viewport): style.css hides the status line.
document.documentElement.classList.toggle("kb", !!vv && Math.abs(vv.scale - 1) <= 0.01 && vv.height < document.documentElement.clientHeight - 120);
if (!vv || Math.abs(vv.scale - 1) > 0.01) { el.style.height = ""; el.style.top = ""; }
else {
// Whole px, rounded down, so the page never runs past the screen's bottom edge.
@@ -145,19 +147,16 @@ function useKeyBar(mobile: boolean) {
}
/**
* The page's height in an iOS home screen app (standalone, which covers the
* whole screen: viewport-fit=cover, black-translucent): the screen's height,
* whole px, unless the on-screen keyboard is up. iOS can report a viewport
* that is shorter than the screen there (by the status bar, or a band left
* after the keyboard closed), which would leave a dead strip at the bottom.
* Undefined elsewhere, and when the window is not the whole screen's width
* (iPad Split View).
* The page's height in an iOS home screen app (standalone): the layout
* viewport's (what a fixed element with inset 0 fills), unless the on-screen
* keyboard is up. The visual viewport can stay short after the keyboard
* closed, which would leave a dead strip at the bottom. Not the screen's
* height: the viewport can be shorter (index.html's status bar style), and
* what is past it is not shown. Undefined elsewhere.
*/
function standaloneHeight(vvHeight: number): number | undefined {
if ((navigator as Navigator & { standalone?: boolean }).standalone !== true) return;
const long = Math.max(screen.width, screen.height), short = Math.min(screen.width, screen.height);
const [w, full] = innerWidth <= innerHeight ? [short, long] : [long, short];
if (Math.abs(innerWidth - w) > 1) return;
const full = document.documentElement.clientHeight;
// Only a focused field can have the keyboard up, and it takes well over 120 px.
const el = document.activeElement as HTMLElement | null;
const editable = !!el && (el.isContentEditable || el.tagName === "INPUT" || el.tagName === "TEXTAREA");

View File

@@ -40,13 +40,30 @@
/* A macOS window outside fullscreen (main.tsx): its bottom corners are round. */
:root.mac-window { --sc: 8px; }
/* iOS (only its WebKit knows -webkit-touch-callout): the page keeps the top
safe area (status bar, notch, Dynamic Island) but takes the whole height
below it. The status line goes down to the bottom edge, over the home
indicator, and its round corners may cut into it, so it moves its ends in
by half the bottom inset (17 px on a Face ID iPhone in portrait). */
safe area (status bar, notch, Dynamic Island) and three quarters of the
bottom one (25 px on a Face ID iPhone in portrait). The status line's
background goes down to the bottom edge, over the home indicator, with its
contents that far above it, clear of the round corners, which it also
keeps its ends away from by half the bottom inset. Not while the
on-screen keyboard is up (App.tsx sets kb): nothing is at the screen's
bottom edge then. */
@supports (-webkit-touch-callout: none) {
:root { --sb: 0px; --sc: calc(env(safe-area-inset-bottom, 0px) / 2); }
:root { --sb: calc(env(safe-area-inset-bottom, 0px) * 0.75); --sc: calc(env(safe-area-inset-bottom, 0px) / 2); }
:root.kb { --sb: 0px; --sc: 0px; }
/* A home screen app (iOS 26+): iOS fades the page's top 20 px or so under
the status bar, and a page cannot turn that off, so what is at the top
starts below it. */
@media (display-mode: standalone) {
:root { --st: calc(env(safe-area-inset-top, 0px) + 24px); }
}
/* Below the status line's contents: a line like the one on its top, and the page's black down to the edge. */
#bar::after {
content: ""; position: absolute; inset: auto 0 0 0; height: var(--sb); pointer-events: none;
border-top: 1px solid var(--color-line); background: var(--color-bg);
}
}
/* The on-screen keyboard is up (App.tsx): the terminal gets the status line's height (the key bar stays). */
:root.kb #bar { display: none; }
/* Touch (config.ts: a coarse pointer or a mobile user agent): a taller status line with wider targets. */
@media (pointer: coarse) { :root { --bar-h: 38px; } }
:root:has(#app.mobile) { --bar-h: 38px; }