fix(webui): preserve viewport position through keyboard rotation
This commit is contained in:
1 parent
d07fac940f
commit
eec1d13aca
4 files changed
+22
-4
No files matched your search
+2
-2
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
};
|
||||
|
||||
@@ -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("");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user