From e7d08a7ecd83ec83182da4abc9d17efc3189ec17 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sun, 19 Jul 2026 16:06:20 -0500 Subject: [PATCH] attempt 4 that shall surely work --- src/app/styles/edgeToEdgeInsets.test.ts | 8 +++++- src/app/utils/iosPwaViewport.ts | 35 +++++++++++++++++++++++++ src/index.css | 2 +- src/index.tsx | 2 ++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/app/utils/iosPwaViewport.ts diff --git a/src/app/styles/edgeToEdgeInsets.test.ts b/src/app/styles/edgeToEdgeInsets.test.ts index 6f71d75e1..76eb80ad6 100644 --- a/src/app/styles/edgeToEdgeInsets.test.ts +++ b/src/app/styles/edgeToEdgeInsets.test.ts @@ -64,10 +64,16 @@ describe('android edge-to-edge inset contract', () => { it('extends only standalone iOS PWAs to the dynamic viewport bottom', () => { const indexCss = readWorkspaceFile('src/index.css'); + const indexTsx = readWorkspaceFile('src/index.tsx'); + const iosPwaViewport = readWorkspaceFile('src/app/utils/iosPwaViewport.ts'); expect(indexCss).toContain('@media (display-mode: standalone)'); expect(indexCss).toContain('@supports (-webkit-touch-callout: none)'); - expect(indexCss).toContain('height: 100dvh'); + expect(indexCss).toContain('var(--sable-ios-pwa-viewport-height, 100dvh)'); + expect(indexTsx).toContain('installIosPwaViewportHeight();'); + expect(iosPwaViewport).toContain("window.matchMedia('(display-mode: standalone)').matches"); + expect(iosPwaViewport).toContain('viewport.height + viewport.offsetTop'); + expect(iosPwaViewport).toContain("window.setTimeout(updateHeight, 350)"); }); it('removes the scattered safe-area css consumers', () => { diff --git a/src/app/utils/iosPwaViewport.ts b/src/app/utils/iosPwaViewport.ts new file mode 100644 index 000000000..0bf285913 --- /dev/null +++ b/src/app/utils/iosPwaViewport.ts @@ -0,0 +1,35 @@ +const IOS_PWA_VIEWPORT_HEIGHT = '--sable-ios-pwa-viewport-height'; + +const isStandaloneIosPwa = (): boolean => + window.matchMedia('(display-mode: standalone)').matches && + CSS.supports('-webkit-touch-callout: none'); + +export function installIosPwaViewportHeight(): void { + if (!isStandaloneIosPwa()) return; + + let frame = 0; + let settleTimer = 0; + + const updateHeight = () => { + frame = 0; + const viewport = window.visualViewport; + const height = viewport ? viewport.height + viewport.offsetTop : window.innerHeight; + document.documentElement.style.setProperty(IOS_PWA_VIEWPORT_HEIGHT, `${Math.round(height)}px`); + }; + + const scheduleUpdate = () => { + if (frame) cancelAnimationFrame(frame); + frame = requestAnimationFrame(updateHeight); + + window.clearTimeout(settleTimer); + settleTimer = window.setTimeout(updateHeight, 350); + }; + + updateHeight(); + window.addEventListener('resize', scheduleUpdate); + window.addEventListener('orientationchange', scheduleUpdate); + window.visualViewport?.addEventListener('resize', scheduleUpdate); + window.visualViewport?.addEventListener('scroll', scheduleUpdate); + document.addEventListener('focusin', scheduleUpdate); + document.addEventListener('focusout', scheduleUpdate); +} diff --git a/src/index.css b/src/index.css index 12c1d2310..a80a37d10 100755 --- a/src/index.css +++ b/src/index.css @@ -63,7 +63,7 @@ body { html, body, #root { - height: 100dvh; + height: var(--sable-ios-pwa-viewport-height, 100dvh); } } } diff --git a/src/index.tsx b/src/index.tsx index 7a292d816..036d41cbb 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -23,6 +23,7 @@ import { registerMatrixUriProtocol } from './app/plugins/matrix-uri'; import { initTauriMediaSession } from './app/utils/tauriMediaAuth'; import { registerAppServiceWorker } from './serviceWorkerBootstrap'; import { hasServiceWorker } from './app/utils/platform'; +import { installIosPwaViewportHeight } from './app/utils/iosPwaViewport'; enableMapSet(); installConsolePasteScamWarning(); @@ -30,6 +31,7 @@ registerMatrixUriProtocol(); const log = createLogger('index'); document.body.classList.add(configClass, varsClass); +installIosPwaViewportHeight(); registerAppServiceWorker();