Fix infinite recomposition when on top of the timeline.

This commit is contained in:
Benoit Marty 2023-07-03 13:32:59 +02:00 committed by Benoit Marty
parent d66d28db72
commit 76e4c684d0

View file

@ -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) {