Add scrolling to newest case

Display cases in reverse chronological order for better UX. Scroll to
the last item when data is loaded.
This commit is contained in:
2026-04-24 14:29:46 +02:00
parent f653a6a447
commit 50fbc2690e
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -40,6 +41,17 @@ fun CaseListScreen(
val cases by CaseStoreStub.cases.collectAsStateWithLifecycle()
val listState = rememberScalingLazyListState()
// Display oldest-first so the newest entry sits next to the `Neu` EdgeButton.
// Store invariant (lastActivityAt desc) stays untouched for Tile / Complication consumers.
val displayed = cases.asReversed()
// Scroll to the newest entry (now at the bottom) once data is available.
LaunchedEffect(displayed.isNotEmpty()) {
if (displayed.isNotEmpty()) {
listState.scrollToItem(displayed.lastIndex)
}
}
ScreenScaffold(
scrollState = listState,
edgeButton = {
@@ -47,8 +59,9 @@ fun CaseListScreen(
Text("● Neu")
}
},
edgeButtonSpacing = 4.dp,
) { contentPadding ->
if (cases.isEmpty()) {
if (displayed.isEmpty()) {
EmptyState(onNewCase)
} else {
ScalingLazyColumn(
@@ -58,7 +71,7 @@ fun CaseListScreen(
verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterVertically),
modifier = Modifier.fillMaxSize(),
) {
items(cases, key = { it.caseId }) { case ->
items(displayed, key = { it.caseId }) { case ->
CaseRow(case, onTap = { onCaseTap(case.caseId) })
}
}