diff --git a/docs/webui.md b/docs/webui.md index 488a415d7..afc1b0deb 100644 --- a/docs/webui.md +++ b/docs/webui.md @@ -192,8 +192,8 @@ On touch devices with Visual Viewport support, the app follows the visible area when the on-screen keyboard opens or pans the page. Navigation and the composer stay in view while messages scroll independently. In very short viewports (such as landscape with the keyboard open), scroll within the composer to reach its -controls. Pinch zoom keeps the existing -layout instead of resizing it to the magnified area; normal fitting resumes when +controls. Pinch zoom keeps the existing layout instead of resizing it to the +magnified area; normal fitting resumes when you return to the default zoom. Desktop and native-host layout remain unchanged. Open the context indicator beside the composer model badge to see how much of diff --git a/webui/src/globals.css b/webui/src/globals.css index 6dabb9626..d3055cd89 100644 --- a/webui/src/globals.css +++ b/webui/src/globals.css @@ -136,7 +136,7 @@ min-height: 2.75rem; } - #root.visual-viewport .workbench-composer-footer { + #root.short-visual-viewport .workbench-composer-footer { max-height: max(0px, calc(var(--app-viewport-height) - 2.75rem)); overflow-y: auto; } diff --git a/webui/src/hooks/useAppViewport.ts b/webui/src/hooks/useAppViewport.ts index a00814359..c833724a4 100644 --- a/webui/src/hooks/useAppViewport.ts +++ b/webui/src/hooks/useAppViewport.ts @@ -15,8 +15,13 @@ export function useAppViewport() { // user's magnified viewport. Resume fitting when the scale returns to 1. if (viewport.scale !== 1) return; root.style.setProperty("--app-viewport-height", `${viewport.height}px`); - root.style.setProperty("--app-viewport-top", `${viewport.offsetTop}px`); + // WebKit can report a negative offset after rotating a focused PWA. + // Do not move the navigation above the top edge with that overscroll. + root.style.setProperty("--app-viewport-top", `${Math.max(0, viewport.offsetTop)}px`); root.classList.add("visual-viewport"); + // Only the keyboard's shortest layouts need a scrollable composer. + // Normal layouts must let the command and mention palettes overflow. + root.classList.toggle("short-visual-viewport", viewport.height < 240); }; update(); viewport.addEventListener("resize", update); @@ -25,6 +30,7 @@ export function useAppViewport() { viewport.removeEventListener("resize", update); viewport.removeEventListener("scroll", update); root.classList.remove("visual-viewport"); + root.classList.remove("short-visual-viewport"); root.style.removeProperty("--app-viewport-height"); root.style.removeProperty("--app-viewport-top"); }; diff --git a/webui/src/tests/useAppViewport.test.tsx b/webui/src/tests/useAppViewport.test.tsx index 9bfd0b1d4..bc9419aef 100644 --- a/webui/src/tests/useAppViewport.test.tsx +++ b/webui/src/tests/useAppViewport.test.tsx @@ -62,6 +62,17 @@ describe("app visual viewport", () => { expect(root.style.getPropertyValue("--app-viewport-height")).toBe("320px"); }); + it("keeps navigation below the top edge when a focused PWA rotates with negative WebKit overscroll", () => { + render(, { container: root }); + resize(128, -68); + expect(root).toHaveClass("short-visual-viewport"); + expect(root.style.getPropertyValue("--app-viewport-height")).toBe("128px"); + expect(root.style.getPropertyValue("--app-viewport-top")).toBe("0px"); + resize(428, 416); + expect(root).not.toHaveClass("short-visual-viewport"); + expect(root.style.getPropertyValue("--app-viewport-top")).toBe("416px"); + }); + it.each(["desktop", "native", "unsupported"])("leaves %s layout ownership unchanged", (kind) => { touch = kind !== "desktop"; native = kind === "native"; @@ -85,6 +96,7 @@ describe("app visual viewport", () => { unmount(); resize(746, 0); expect(root).not.toHaveClass("visual-viewport"); + expect(root).not.toHaveClass("short-visual-viewport"); expect(root.style.getPropertyValue("--app-viewport-top")).toBe(""); }); });