diff --git a/android/src/screens/ChatScreen.tsx b/android/src/screens/ChatScreen.tsx index 70d4ff1..cbd1b26 100644 --- a/android/src/screens/ChatScreen.tsx +++ b/android/src/screens/ChatScreen.tsx @@ -377,12 +377,21 @@ const ChatScreen: React.FC = () => { useEffect(() => { 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(() => { + const scrollToBottom = () => { + try { + flatListRef.current?.scrollToIndex({ + index: messages.length - 1, + animated: !isInitial, + viewPosition: 1, // 1 = Item am unteren Rand + }); + } catch { + // Fallback wenn Index nicht berechnet werden kann flatListRef.current?.scrollToEnd({ animated: !isInitial }); - }, delay); + } + }; + const delays = isInitial ? [200, 500, 1000] : [150]; + for (const delay of delays) { + setTimeout(scrollToBottom, delay); } } lastMessageCount.current = messages.length; @@ -691,6 +700,11 @@ const ChatScreen: React.FC = () => { showsVerticalScrollIndicator={false} onScrollBeginDrag={handleScrollBeginDrag} onScrollEndDrag={handleScrollEndDrag} + onScrollToIndexFailed={(info) => { + setTimeout(() => { + flatListRef.current?.scrollToEnd({ animated: false }); + }, 200); + }} ListEmptyComponent={ {'\uD83E\uDD16'}