mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Timeline: add autoscroll on new messages
This commit is contained in:
+40
-21
@@ -224,29 +224,32 @@ fun TimelineItems(
|
|||||||
onReachedLoadMore: () -> Unit,
|
onReachedLoadMore: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
LazyColumn(
|
Box(modifier = modifier.fillMaxWidth()) {
|
||||||
modifier = modifier.fillMaxWidth(),
|
LazyColumn(
|
||||||
state = lazyListState,
|
modifier = modifier.fillMaxWidth(),
|
||||||
horizontalAlignment = Alignment.Start,
|
state = lazyListState,
|
||||||
verticalArrangement = Arrangement.Bottom,
|
horizontalAlignment = Alignment.Start,
|
||||||
reverseLayout = true
|
verticalArrangement = Arrangement.Bottom,
|
||||||
) {
|
reverseLayout = true
|
||||||
items(
|
) {
|
||||||
items = timelineItems,
|
items(
|
||||||
contentType = { timelineItem -> timelineItem.contentType() },
|
items = timelineItems,
|
||||||
key = { timelineItem -> timelineItem.key() },
|
contentType = { timelineItem -> timelineItem.contentType() },
|
||||||
) { timelineItem ->
|
key = { timelineItem -> timelineItem.key() },
|
||||||
TimelineItemRow(
|
) { timelineItem ->
|
||||||
timelineItem = timelineItem,
|
TimelineItemRow(
|
||||||
onClick = onClick,
|
timelineItem = timelineItem,
|
||||||
onLongClick = onLongClick
|
onClick = onClick,
|
||||||
)
|
onLongClick = onLongClick
|
||||||
}
|
)
|
||||||
if (hasMoreToLoad) {
|
}
|
||||||
item {
|
if (hasMoreToLoad) {
|
||||||
MessagesLoadingMoreIndicator(onReachedLoadMore)
|
item {
|
||||||
|
MessagesLoadingMoreIndicator(onReachedLoadMore)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MessagesScrollHelper(lazyListState = lazyListState, timelineItems = timelineItems)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user