Scroll on history change

This commit is contained in:
Sad Ellie 2023-05-26 10:00:27 +03:00
parent 97aac49b19
commit 29fb953644

View File

@ -30,6 +30,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
@ -123,11 +124,15 @@ private fun HistoryListContent(
formatterSymbols: FormatterSymbols, formatterSymbols: FormatterSymbols,
historyItemHeightCallback: (Int) -> Unit historyItemHeightCallback: (Int) -> Unit
) { ) {
val state = rememberLazyListState()
val firstItem by remember(historyItems) { mutableStateOf(historyItems.first()) } val firstItem by remember(historyItems) { mutableStateOf(historyItems.first()) }
val restOfTheItems by remember(firstItem) { mutableStateOf(historyItems.drop(1)) } val restOfTheItems by remember(firstItem) { mutableStateOf(historyItems.drop(1)) }
LaunchedEffect(historyItems) { state.scrollToItem(0) }
LazyColumn( LazyColumn(
modifier = modifier, modifier = modifier,
state = state,
reverseLayout = true, reverseLayout = true,
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.Bottom) verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.Bottom)
) { ) {