Assigned
Status Update
Comments
wa...@gmail.com <wa...@gmail.com> #2
My version is
kotlin = "2.1.0"
ksp = "2.1.0-1.0.29"
compose-bom-alpha = "2024.12.01"
compose-navigation = "2.8.5"
foundation = 1.8.0-alpha07
be...@google.com <be...@google.com> #3
Can you please update your sample to include the navigation code as well to make it easier to reproduce the issue?
Description
I believe that LazyVerticalStaggeredGrid should properly save the positional information of previously laid-out items, rather than just recording an initial visible position. Since the item heights in LazyVerticalStaggeredGrid are not fixed, losing the previous layout order after the page is restored leads to items being repeatedly re-laid out when scrolling back up. This behavior is counterintuitive. From the user’s perspective, if I scroll to a certain item, navigate to a detail page, and then return, the items jumping around while scrolling back up feels very jarring and unpleasant.
If there’s any way to maintain the previous layout order during restore, please let me know. I’m waiting online and quite anxious. Thank you so much!
LazyVerticalStaggeredGrid(
state = gridState,
columns = StaggeredGridCells.Adaptive(150.dp),
modifier = Modifier.fillMaxSize()
) {
items(50) {
OutlinedCard(
onClick = { navOtherScreenAndBack() },
modifier = Modifier
.fillMaxWidth()
.aspectRatio((it % 3 + 1) / 2f)
) {
Box(
modifier = Modifier
.fillMaxSize()
.background(if (it % 2 == 0) Color.Blue else Color.Gray)
) {
Text(text = "Index: $it", modifier = Modifier.align(Alignment.Center))
}
}
}
}