Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: persist scroll state #170

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need two different states? I'm also fine with it, just asking.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it myself and I think it is easier with two states 👍


AnimatedContent(
targetState = isGridMode,
transitionSpec = {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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(
Expand Down