Improve mobile keyboard handling and viewport detection
Build And Push Image / docker (push) Successful in 3m3s
Details
Build And Push Image / docker (push) Successful in 3m3s
Details
- Disable transitions and make menu persistent on mobile devices - Add keyboard open/close detection to prevent unwanted viewport updates - Differentiate between keyboard events and actual viewport changes - Improve resize debouncing with longer delays for mobile - Handle orientation changes separately from keyboard events
This commit is contained in:
parent
623ad9c3fd
commit
006d4cf1ff
|
|
@ -24,8 +24,10 @@
|
||||||
location="bottom start"
|
location="bottom start"
|
||||||
:offset="4"
|
:offset="4"
|
||||||
:min-width="mobileDetection.isMobile ? '90vw' : '280'"
|
:min-width="mobileDetection.isMobile ? '90vw' : '280'"
|
||||||
transition="fade-transition"
|
:transition="mobileDetection.isMobile ? 'none' : 'fade-transition'"
|
||||||
:no-click-animation="true"
|
:no-click-animation="true"
|
||||||
|
:persistent="mobileDetection.isMobile"
|
||||||
|
:attach="false"
|
||||||
>
|
>
|
||||||
<template #activator="{ props: menuProps }">
|
<template #activator="{ props: menuProps }">
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
|
|
@ -83,17 +83,46 @@ function setupListeners() {
|
||||||
|
|
||||||
let resizeTimeout: NodeJS.Timeout;
|
let resizeTimeout: NodeJS.Timeout;
|
||||||
let lastHeight = window.innerHeight;
|
let lastHeight = window.innerHeight;
|
||||||
|
let initialHeight = window.innerHeight;
|
||||||
|
let keyboardOpen = false;
|
||||||
|
|
||||||
const handleResize = () => {
|
const handleResize = () => {
|
||||||
|
// Don't handle resize if we're in the middle of a transition
|
||||||
|
if (document.hidden) return;
|
||||||
|
|
||||||
clearTimeout(resizeTimeout);
|
clearTimeout(resizeTimeout);
|
||||||
|
|
||||||
// Debounce and only update if height actually changed
|
// Debounce with longer delay for mobile
|
||||||
|
const debounceDelay = globalState.isMobile ? 300 : 150;
|
||||||
|
|
||||||
resizeTimeout = setTimeout(() => {
|
resizeTimeout = setTimeout(() => {
|
||||||
const newHeight = window.innerHeight;
|
const newHeight = window.innerHeight;
|
||||||
|
const heightDiff = newHeight - lastHeight;
|
||||||
|
const absoluteDiff = Math.abs(heightDiff);
|
||||||
|
|
||||||
// Only update if there's a significant change (more than 20px)
|
// Detect keyboard open/close on mobile
|
||||||
// This prevents minor fluctuations from triggering updates
|
if (globalState.isMobile) {
|
||||||
if (Math.abs(newHeight - lastHeight) > 20) {
|
// Keyboard likely opened (viewport got smaller)
|
||||||
|
if (heightDiff < -100 && newHeight < initialHeight * 0.75) {
|
||||||
|
keyboardOpen = true;
|
||||||
|
// Don't trigger viewport updates for keyboard changes
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard likely closed (viewport got bigger)
|
||||||
|
if (heightDiff > 100 && keyboardOpen) {
|
||||||
|
keyboardOpen = false;
|
||||||
|
// Don't trigger viewport updates for keyboard changes
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only update for significant non-keyboard changes (more than 50px)
|
||||||
|
// or orientation changes (height differs significantly from initial)
|
||||||
|
const isOrientationChange = absoluteDiff > initialHeight * 0.3;
|
||||||
|
const isSignificantChange = absoluteDiff > 50;
|
||||||
|
|
||||||
|
if (isOrientationChange || (isSignificantChange && !keyboardOpen)) {
|
||||||
lastHeight = newHeight;
|
lastHeight = newHeight;
|
||||||
globalState.viewportHeight = newHeight;
|
globalState.viewportHeight = newHeight;
|
||||||
|
|
||||||
|
|
@ -102,8 +131,13 @@ function setupListeners() {
|
||||||
const vh = newHeight * 0.01;
|
const vh = newHeight * 0.01;
|
||||||
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update initial height after orientation change
|
||||||
|
if (isOrientationChange) {
|
||||||
|
initialHeight = newHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 150); // Increased debounce time
|
}, debounceDelay);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add resize listener with passive option for better performance
|
// Add resize listener with passive option for better performance
|
||||||
|
|
@ -112,8 +146,10 @@ function setupListeners() {
|
||||||
// Also listen for orientation changes on mobile
|
// Also listen for orientation changes on mobile
|
||||||
if (globalState.isMobile) {
|
if (globalState.isMobile) {
|
||||||
window.addEventListener('orientationchange', () => {
|
window.addEventListener('orientationchange', () => {
|
||||||
|
// Reset keyboard state on orientation change
|
||||||
|
keyboardOpen = false;
|
||||||
// Wait for orientation change to complete
|
// Wait for orientation change to complete
|
||||||
setTimeout(handleResize, 100);
|
setTimeout(handleResize, 200);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue