From 247794767377b919effc1a6a7bbdbb8ba345ab60 Mon Sep 17 00:00:00 2001 From: Ankur Date: Mon, 18 Mar 2024 21:16:06 -0700 Subject: [PATCH] Feat: remember scroll state across composition --- .../de/dbauer/expensetracker/ui/RecurringExpenseOverview.kt | 6 ++++++ .../ui/upcomingexpenses/UpcomingPaymentsScreen.kt | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/app/src/main/java/de/dbauer/expensetracker/ui/RecurringExpenseOverview.kt b/app/src/main/java/de/dbauer/expensetracker/ui/RecurringExpenseOverview.kt index f801886..1c929fb 100644 --- a/app/src/main/java/de/dbauer/expensetracker/ui/RecurringExpenseOverview.kt +++ b/app/src/main/java/de/dbauer/expensetracker/ui/RecurringExpenseOverview.kt @@ -19,6 +19,7 @@ import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan import androidx.compose.foundation.lazy.staggeredgrid.items +import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.MaterialTheme @@ -57,6 +58,10 @@ fun RecurringExpenseOverview( contentPadding: PaddingValues = PaddingValues(0.dp), ) { val fadeDuration: Int = integerResource(id = R.integer.overview_list_grid_toggle_fade_anim_duration) + + val listState = rememberLazyStaggeredGridState() + val gridState = rememberLazyStaggeredGridState() + AnimatedContent( targetState = isGridMode, transitionSpec = { @@ -81,6 +86,7 @@ fun RecurringExpenseOverview( } else { StaggeredGridCells.Fixed(1) }, + state = if (targetValue) gridState else listState, verticalItemSpacing = dimensionResource(id = R.dimen.overview_list_grid_vertical_item_spacing), horizontalArrangement = Arrangement.spacedBy( diff --git a/app/src/main/java/de/dbauer/expensetracker/ui/upcomingexpenses/UpcomingPaymentsScreen.kt b/app/src/main/java/de/dbauer/expensetracker/ui/upcomingexpenses/UpcomingPaymentsScreen.kt index e1c2b93..56e3db0 100644 --- a/app/src/main/java/de/dbauer/expensetracker/ui/upcomingexpenses/UpcomingPaymentsScreen.kt +++ b/app/src/main/java/de/dbauer/expensetracker/ui/upcomingexpenses/UpcomingPaymentsScreen.kt @@ -20,6 +20,7 @@ import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan import androidx.compose.foundation.lazy.staggeredgrid.items +import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.rounded.List import androidx.compose.material3.Card @@ -88,6 +89,10 @@ private fun UpcomingPaymentsOverview( contentPadding: PaddingValues = PaddingValues(0.dp), ) { val fadeDuration: Int = integerResource(id = R.integer.overview_list_grid_toggle_fade_anim_duration) + + val listState = rememberLazyStaggeredGridState() + val gridState = rememberLazyStaggeredGridState() + AnimatedContent( targetState = isGridMode, transitionSpec = { @@ -112,6 +117,7 @@ private fun UpcomingPaymentsOverview( } else { StaggeredGridCells.Fixed(1) }, + state = if (targetValue) gridState else listState, verticalItemSpacing = dimensionResource(id = R.dimen.overview_list_grid_vertical_item_spacing), horizontalArrangement = Arrangement.spacedBy(