feat: handle ios safari keyboard

This commit is contained in:
Tim
2025-08-05 15:15:57 +08:00
parent caba1c6658
commit 9b31df28aa
2 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
export function initIOSKeyboardFix() {
if (typeof window === 'undefined' || !window.visualViewport) return;
const ua = navigator.userAgent || '';
const isIOS = /iP(ad|hone|od)/.test(ua);
if (!isIOS) return;
const viewport = window.visualViewport;
const adjustScroll = () => {
window.scrollTo(0, viewport.offsetTop);
};
viewport.addEventListener('resize', adjustScroll);
viewport.addEventListener('scroll', adjustScroll);
let lastScrollY = 0;
document.addEventListener('focusin', () => {
lastScrollY = window.scrollY;
});
document.addEventListener('focusout', () => {
window.scrollTo(0, lastScrollY);
});
}