MCPcopy
hub / github.com/Dimillian/CodexMonitor / syncMobileViewportHeight

Function syncMobileViewportHeight

src/main.tsx:41–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41function syncMobileViewportHeight() {
42 if (!isMobilePlatform() || typeof window === "undefined" || typeof document === "undefined") {
43 return;
44 }
45
46 let rafHandle = 0;
47
48 const setViewportHeight = () => {
49 const visualViewport = window.visualViewport;
50 const viewportHeight = visualViewport
51 ? visualViewport.height + visualViewport.offsetTop
52 : window.innerHeight;
53 const nextHeight = Math.round(viewportHeight);
54 document.documentElement.style.setProperty("--app-height", `${nextHeight}px`);
55 };
56
57 const scheduleViewportHeight = () => {
58 if (rafHandle) {
59 return;
60 }
61 rafHandle = window.requestAnimationFrame(() => {
62 rafHandle = 0;
63 setViewportHeight();
64 });
65 };
66
67 const setComposerFocusState = () => {
68 const activeElement = document.activeElement;
69 const isComposerTextareaFocused =
70 activeElement instanceof HTMLTextAreaElement &&
71 activeElement.closest(".composer") !== null;
72 document.documentElement.dataset.mobileComposerFocus = isComposerTextareaFocused
73 ? "true"
74 : "false";
75 };
76
77 setViewportHeight();
78 setComposerFocusState();
79 window.addEventListener("resize", scheduleViewportHeight, { passive: true });
80 window.addEventListener("orientationchange", scheduleViewportHeight, { passive: true });
81 window.visualViewport?.addEventListener("resize", scheduleViewportHeight, { passive: true });
82 window.visualViewport?.addEventListener("scroll", scheduleViewportHeight, { passive: true });
83 document.addEventListener("focusin", setComposerFocusState);
84 document.addEventListener("focusout", () => {
85 requestAnimationFrame(setComposerFocusState);
86 });
87}
88
89disableMobileZoomGestures();
90syncMobileViewportHeight();

Callers 1

main.tsxFile · 0.85

Calls 3

isMobilePlatformFunction · 0.90
setViewportHeightFunction · 0.85
setComposerFocusStateFunction · 0.85

Tested by

no test coverage detected