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]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
if (!window.visualViewport) return;
|
if (!window.visualViewport) return;
|
||||||
const onResize = () => {
|
const onResize = () => {
|
||||||
// Kleine Verzögerung damit Layout neu berechnet wird
|
// Prüfe ob bottomRef nah am sichtbaren Bereich war (= User war am Ende)
|
||||||
setTimeout(() => scrollToBottom('instant'), 50);
|
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);
|
window.visualViewport.addEventListener('resize', onResize);
|
||||||
return () => window.visualViewport.removeEventListener('resize', onResize);
|
return () => window.visualViewport.removeEventListener('resize', onResize);
|
||||||
|
|||||||
Reference in New Issue
Block a user