fix(webui): preserve viewport position through keyboard rotation

This commit is contained in:
Xubin Ren committed 2026-10-04 10:40:09 +08:00
1 parent d07fac940f
commit eec1d13aca
4 files changed
+22 -4

No files matched your search

+1 -1
View File
@@ -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;
}
+7 -1
View File
@@ -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");
};
+12
View File
@@ -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(<AppSurface />, { 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("");
});
});