From 29fb953644f59eaf0612c314f8e6148f47ef1348 Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Fri, 26 May 2023 10:00:27 +0300 Subject: [PATCH] Scroll on history change --- .../unitto/feature/calculator/components/HistoryList.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/HistoryList.kt b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/HistoryList.kt index dbc5597f..6666d729 100644 --- a/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/HistoryList.kt +++ b/feature/calculator/src/main/java/com/sadellie/unitto/feature/calculator/components/HistoryList.kt @@ -30,6 +30,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.BasicTextField import androidx.compose.material.icons.Icons @@ -123,11 +124,15 @@ private fun HistoryListContent( formatterSymbols: FormatterSymbols, historyItemHeightCallback: (Int) -> Unit ) { + val state = rememberLazyListState() val firstItem by remember(historyItems) { mutableStateOf(historyItems.first()) } val restOfTheItems by remember(firstItem) { mutableStateOf(historyItems.drop(1)) } + LaunchedEffect(historyItems) { state.scrollToItem(0) } + LazyColumn( modifier = modifier, + state = state, reverseLayout = true, verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.Bottom) ) {