diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt index 2dffc9b64c..9cd42ad354 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt @@ -233,12 +233,9 @@ internal fun BoxScope.TimelineScrollHelper( val isScrollFinished by remember { derivedStateOf { !lazyListState.isScrollInProgress } } val shouldAutoScrollToBottom by remember { derivedStateOf { lazyListState.firstVisibleItemIndex < 2 } } - LaunchedEffect(timelineItems, firstVisibleItemIndex, isScrollFinished) { + LaunchedEffect(timelineItems, firstVisibleItemIndex) { if (!isScrollFinished) return@LaunchedEffect - // Notify the parent composable about the first visible item index when scrolling finishes - onScrollFinishedAt(firstVisibleItemIndex) - // Auto-scroll when new timeline items appear if (shouldAutoScrollToBottom) { coroutineScope.launch { @@ -246,6 +243,12 @@ internal fun BoxScope.TimelineScrollHelper( } } } + LaunchedEffect(isScrollFinished) { + if (!isScrollFinished) return@LaunchedEffect + + // Notify the parent composable about the first visible item index when scrolling finishes + onScrollFinishedAt(firstVisibleItemIndex) + } // Jump to bottom button (display also in previews) if (!shouldAutoScrollToBottom || LocalInspectionMode.current) {