fix: keyboard scroll nur wenn User bereits am Ende war
This commit is contained in:
@@ -227,12 +227,17 @@ export default function Nachrichten({ toast, mobile, nav }) {
|
||||
}
|
||||
}, [messages.length, activeUser?.id]);
|
||||
|
||||
// Wenn Handy-Tastatur aufklappt (visualViewport schrumpft) → ans Ende scrollen
|
||||
// Wenn Handy-Tastatur aufklappt → ans Ende scrollen NUR wenn schon am Ende war
|
||||
useEffect(() => {
|
||||
if (!window.visualViewport) return;
|
||||
const onResize = () => {
|
||||
// Kleine Verzögerung damit Layout neu berechnet wird
|
||||
setTimeout(() => scrollToBottom('instant'), 50);
|
||||
// Prüfe ob bottomRef nah am sichtbaren Bereich war (= User war am Ende)
|
||||
if (!bottomRef.current) return;
|
||||
const rect = bottomRef.current.getBoundingClientRect();
|
||||
const wasAtBottom = rect.top <= (window.visualViewport?.height ?? window.innerHeight) + 100;
|
||||
if (wasAtBottom) {
|
||||
setTimeout(() => scrollToBottom('instant'), 50);
|
||||
}
|
||||
};
|
||||
window.visualViewport.addEventListener('resize', onResize);
|
||||
return () => window.visualViewport.removeEventListener('resize', onResize);
|
||||
|
||||
Reference in New Issue
Block a user