From ea4f639fcb50ce0777ce5cf3ce2d2807b55cd1e5 Mon Sep 17 00:00:00 2001 From: duffyduck Date: Sat, 11 Apr 2026 12:07:54 +0200 Subject: [PATCH] fix: Auto-scroll retry with multiple delays (100, 300, 600, 1000ms) FlatList needs time to render - single setTimeout(150) was unreliable. Now tries 4 times on initial load, 2 times for new messages. Co-Authored-By: Claude Opus 4.6 (1M context) --- android/src/screens/ChatScreen.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/android/src/screens/ChatScreen.tsx b/android/src/screens/ChatScreen.tsx index 1ad04e6..70d4ff1 100644 --- a/android/src/screens/ChatScreen.tsx +++ b/android/src/screens/ChatScreen.tsx @@ -373,13 +373,17 @@ const ChatScreen: React.FC = () => { const shouldAutoScroll = useRef(true); const lastMessageCount = useRef(0); - // Bei neuen Nachrichten: sofort nach unten + // Bei neuen Nachrichten oder App-Start: nach unten springen useEffect(() => { - if (messages.length > lastMessageCount.current && shouldAutoScroll.current) { - // Kurzer Delay damit FlatList rendern kann - setTimeout(() => { - flatListRef.current?.scrollToEnd({ animated: messages.length > lastMessageCount.current + 1 ? false : true }); - }, 150); + if (messages.length > 0 && shouldAutoScroll.current) { + const isInitial = lastMessageCount.current === 0; + // Mehrfach versuchen (FlatList braucht Zeit zum Rendern) + const delays = isInitial ? [100, 300, 600, 1000] : [100, 300]; + for (const delay of delays) { + setTimeout(() => { + flatListRef.current?.scrollToEnd({ animated: !isInitial }); + }, delay); + } } lastMessageCount.current = messages.length; }, [messages]);