fix(webui): keep touch app chrome inside the visual viewport

This commit is contained in:
Xubin Ren committed 2026-10-04 10:40:09 +08:00
1 parent 69a368fdf8
commit 4e77584eb7
7 files changed
+157

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import { useLayoutEffect } from "react";
import { useMediaQuery } from "@/hooks/useMediaQuery";
import { isNativeRuntime } from "@/lib/runtime";
/** One viewport owner for navigation, workbench composers and ordinary threads. */
export function useAppViewport() {
const touch = useMediaQuery("(any-pointer: coarse)");
useLayoutEffect(() => {
const viewport = window.visualViewport;
const root = document.getElementById("root");
if (!touch || !viewport || !root || isNativeRuntime()) return;
const update = () => {
// Pinch zoom pans the existing layout; it must not reflow it or chase the
// 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`);
root.classList.add("visual-viewport");
};
update();
viewport.addEventListener("resize", update);
viewport.addEventListener("scroll", update);
return () => {
viewport.removeEventListener("resize", update);
viewport.removeEventListener("scroll", update);
root.classList.remove("visual-viewport");
root.style.removeProperty("--app-viewport-height");
root.style.removeProperty("--app-viewport-top");
};
}, [touch]);
}