Fix infinite recomposition when on top of the timeline.
This commit is contained in:
parent
14d314f87c
commit
b244bdf6a8
1 changed files with 7 additions and 4 deletions
|
|
@ -233,12 +233,9 @@ internal fun BoxScope.TimelineScrollHelper(
|
||||||
val isScrollFinished by remember { derivedStateOf { !lazyListState.isScrollInProgress } }
|
val isScrollFinished by remember { derivedStateOf { !lazyListState.isScrollInProgress } }
|
||||||
val shouldAutoScrollToBottom by remember { derivedStateOf { lazyListState.firstVisibleItemIndex < 2 } }
|
val shouldAutoScrollToBottom by remember { derivedStateOf { lazyListState.firstVisibleItemIndex < 2 } }
|
||||||
|
|
||||||
LaunchedEffect(timelineItems, firstVisibleItemIndex, isScrollFinished) {
|
LaunchedEffect(timelineItems, firstVisibleItemIndex) {
|
||||||
if (!isScrollFinished) return@LaunchedEffect
|
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
|
// Auto-scroll when new timeline items appear
|
||||||
if (shouldAutoScrollToBottom) {
|
if (shouldAutoScrollToBottom) {
|
||||||
coroutineScope.launch {
|
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)
|
// Jump to bottom button (display also in previews)
|
||||||
if (!shouldAutoScrollToBottom || LocalInspectionMode.current) {
|
if (!shouldAutoScrollToBottom || LocalInspectionMode.current) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue