From 72aad26c03dd1e990d29dd3a120426ff8c80eb13 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sun, 5 Feb 2023 18:13:08 -0500 Subject: [PATCH] Fixing a bug where the last message is remembered by the Compose when forcing index = 0 on the first element. --- .../vitorpamplona/amethyst/ui/screen/ChatroomFeedView.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ChatroomFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ChatroomFeedView.kt index 1708cce3c..209cabaeb 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ChatroomFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ChatroomFeedView.kt @@ -50,6 +50,11 @@ fun ChatroomFeedView(viewModel: FeedViewModel, accountViewModel: AccountViewMode } } is FeedState.Loaded -> { + LaunchedEffect(state.feed.value.firstOrNull()) { + if (listState.firstVisibleItemIndex <= 1) + listState.animateScrollToItem(0) + } + LazyColumn( contentPadding = PaddingValues( top = 10.dp, @@ -59,7 +64,7 @@ fun ChatroomFeedView(viewModel: FeedViewModel, accountViewModel: AccountViewMode state = listState ) { var previousDate: String = "" - itemsIndexed(state.feed.value, key = { index, item -> if (index == 0) index else item.idHex }) { index, item -> + itemsIndexed(state.feed.value, key = { index, item -> item.idHex }) { index, item -> ChatroomMessageCompose(item, routeForLastRead, accountViewModel = accountViewModel, navController = navController) } }