diff --git a/frontend/src/tools/nachrichten.jsx b/frontend/src/tools/nachrichten.jsx index 16d7ede..11714b0 100644 --- a/frontend/src/tools/nachrichten.jsx +++ b/frontend/src/tools/nachrichten.jsx @@ -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);