Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
Jetpack Compose component(s) used:
val composeBom = platform("androidx.compose:compose-bom:2024.12.01")
implementation(composeBom)
implementation("androidx.paging:paging-compose:3.3.5")
implementation("androidx.navigation:navigation-compose:2.8.5")
Android Studio Build: Build #AI-242.23726.103.2422.12816248, built on December 18, 2024
Kotlin version: 1.9.25
Steps to Reproduce or Code Sample to Reproduce:
Hello,
I'd like to report a stange behaviour when using lazy lists and navigation.
When the list is supplied with a lazy list state coming from outside of the navhost. The scroll position is reset when navigating back in from the destination. It seems that the paging data needs a while to reload it's previous state and during that time it reports 0 as item count which resets the scroll position.
However, when using a list state initializes inside of the navigation (see code sample), this issue does not occur and we retain the scroll position.
In our project the scroll state needs to be global due to requirements. We managed to workaround this by not rendering the LazyColumn if the paged data count is 0 and the source is not idle, however it seems that the behaviour should come out of the box.
Can you please check if this is a bug?
Thanks,
Radovan
setContentView(ComposeView(this).apply {
setContent {
var i by remember { mutableStateOf(false) }
val navController = rememberNavController()
// If lazyListState is initialized here, scroll state is lost when navigating back
val lazyListState = rememberLazyListState()
Surface {
Column {
TextButton(onClick = {
i = !i
when (i) {
false -> navController.popBackStack()
true -> navController.navigate("screenB")
}
})
{ Text("Click!", color = Color.Black) }
NavHost(
startDestination = "screenA",
navController = navController,
builder = {
composable("screenA") {
// If lazyListState is initialized here, scroll state is retained
// val lazyListState = rememberLazyListState()
PagingColumn(items, lazyListState)
}
composable("screenB") {
Box(
Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text("Screen B")
}
}
}
)
}
}
}
})