mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-26 20:06:26 -08:00
aaand another attempt
This commit is contained in:
1 parent
492bb40dc4
commit
85af26037b
2 files changed
+18
-2
No files matched your search
@@ -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)');
|
||||
});
|
||||
|
||||
|
||||
@@ -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`);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user