From 85af26037b06a123d2bedfe543025656f980fdb7 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Sun, 19 Jul 2026 16:17:06 -0500 Subject: [PATCH] aaand another attempt --- src/app/styles/edgeToEdgeInsets.test.ts | 4 +++- src/app/utils/iosPwaViewport.ts | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app/styles/edgeToEdgeInsets.test.ts b/src/app/styles/edgeToEdgeInsets.test.ts index fb49114d3..522d31329 100644 --- a/src/app/styles/edgeToEdgeInsets.test.ts +++ b/src/app/styles/edgeToEdgeInsets.test.ts @@ -72,7 +72,9 @@ describe('android edge-to-edge inset contract', () => { 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('const MIN_KEYBOARD_HEIGHT = 100'); + expect(iosPwaViewport).toContain('const keyboardOpen = fullHeight - visibleHeight'); + expect(iosPwaViewport).toContain('const height = keyboardOpen ? visibleBottom : fullHeight'); expect(iosPwaViewport).toContain('window.setTimeout(updateHeight, 350)'); }); diff --git a/src/app/utils/iosPwaViewport.ts b/src/app/utils/iosPwaViewport.ts index 0bf285913..326884273 100644 --- a/src/app/utils/iosPwaViewport.ts +++ b/src/app/utils/iosPwaViewport.ts @@ -1,4 +1,5 @@ const IOS_PWA_VIEWPORT_HEIGHT = '--sable-ios-pwa-viewport-height'; +const MIN_KEYBOARD_HEIGHT = 100; const isStandaloneIosPwa = (): boolean => window.matchMedia('(display-mode: standalone)').matches && @@ -9,11 +10,24 @@ export function installIosPwaViewportHeight(): void { let frame = 0; let settleTimer = 0; + let fullHeight = 0; + let viewportWidth = window.innerWidth; const updateHeight = () => { frame = 0; const viewport = window.visualViewport; - const height = viewport ? viewport.height + viewport.offsetTop : window.innerHeight; + const visibleHeight = viewport?.height ?? window.innerHeight; + const visibleBottom = visibleHeight + (viewport?.offsetTop ?? 0); + + if (window.innerWidth !== viewportWidth) { + viewportWidth = window.innerWidth; + fullHeight = visibleBottom; + } + + const keyboardOpen = fullHeight - visibleHeight > MIN_KEYBOARD_HEIGHT; + if (!keyboardOpen) fullHeight = Math.max(fullHeight, visibleBottom); + + const height = keyboardOpen ? visibleBottom : fullHeight; document.documentElement.style.setProperty(IOS_PWA_VIEWPORT_HEIGHT, `${Math.round(height)}px`); };