Timeline: add autoscroll on new messages
This commit is contained in:
parent
b294ad132c
commit
778d2455b0
1 changed files with 40 additions and 21 deletions
|
|
@ -224,6 +224,7 @@ fun TimelineItems(
|
||||||
onReachedLoadMore: () -> Unit,
|
onReachedLoadMore: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
|
Box(modifier = modifier.fillMaxWidth()) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
state = lazyListState,
|
state = lazyListState,
|
||||||
|
|
@ -248,6 +249,8 @@ fun TimelineItems(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MessagesScrollHelper(lazyListState = lazyListState, timelineItems = timelineItems)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MessagesTimelineItemState.key(): String {
|
private fun MessagesTimelineItemState.key(): String {
|
||||||
|
|
@ -455,6 +458,22 @@ fun MessageEventBubble(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
internal fun MessagesScrollHelper(
|
||||||
|
lazyListState: LazyListState,
|
||||||
|
timelineItems: List<MessagesTimelineItemState>,
|
||||||
|
) {
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
val firstVisibleItemIndex by remember { derivedStateOf { lazyListState.firstVisibleItemIndex } }
|
||||||
|
LaunchedEffect(timelineItems, firstVisibleItemIndex) {
|
||||||
|
if (!lazyListState.isScrollInProgress &&
|
||||||
|
firstVisibleItemIndex < 2
|
||||||
|
) coroutineScope.launch {
|
||||||
|
lazyListState.animateScrollToItem(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun MessagesLoadingMoreIndicator(onReachedLoadMore: () -> Unit) {
|
internal fun MessagesLoadingMoreIndicator(onReachedLoadMore: () -> Unit) {
|
||||||
Box(
|
Box(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue