Scroll to top on game activated.

This commit is contained in:
2023-09-27 18:51:26 +02:00
parent 461dc4a30c
commit fa9786de04

View File

@@ -53,6 +53,8 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import me.zobrist.tichucounter.R import me.zobrist.tichucounter.R
import me.zobrist.tichucounter.data.GameWithScores import me.zobrist.tichucounter.data.GameWithScores
@@ -159,23 +161,31 @@ fun HistoryList(
onDeleteAllClicked: () -> Unit, onDeleteAllClicked: () -> Unit,
lazyListState: LazyListState = LazyListState(), lazyListState: LazyListState = LazyListState(),
) { ) {
val scope = rememberCoroutineScope()
Row { Row {
LazyColumn(state = lazyListState) { LazyColumn(state = lazyListState) {
items( items(
items = games, items = games,
key = { it.hashCode() }) { key = { it.game.uid }) { item ->
if (it.game.active) { if (item.game.active) {
HistoryListItem( HistoryListItem(
it, item,
Modifier Modifier
.animateItemPlacement() .animateItemPlacement()
.padding(2.dp) .padding(2.dp)
) )
} else { } else {
DismissibleHistoryListItem( DismissibleHistoryListItem(
it, item,
Modifier.animateItemPlacement(), Modifier.animateItemPlacement(),
onOpenClicked, {
onOpenClicked(it)
scope.launch {
delay(100)
lazyListState.animateScrollToItem(0)
}
},
onDeleteClicked onDeleteClicked
) )
} }