I'm running into an issue on iOS with Koin & compose-navigation where
collectAsStateWithLifecycle
stops getting new values after restoring a view model after navigation.
However, collecting without lifecycle does keep updating
Copy code
@Composable
fun MyScreen(viewModel: MyViewModel = koinViewModel()) {
val scope = rememberCoroutineScope()
// collectLatest: Does Update
scope.launch {
viewModel.uiState.collectLatest { state -> println("collectLatest Id: ${state.id}") }
}
// collectAsState: Does Update
val uiState by viewModel.uiState.collectAsState()
Text("collectAsState Id: ${uiState.id}: ")
// collectAsStateWithLifecycle: Does NOT Update
val uiStateWithLifecycle by viewModel.uiState.collectAsStateWithLifecycle()
Text("collectAsStateWithLifecycle Id: ${uiStateWithLifecycle.id}: ")
}
Any ideas on where I should go looking for a fix?
Christopher Mederos
08/05/2025, 6:22 AM
ended up being related to this bug: https://issuetracker.google.com/issues/421095236
fixed in navigation-compose:2.9.1
used as org.jetbrains.androidx.navigationnavigation compose2.9.0-beta04 in CMP
(which also requires upgrading to compose multiplatform 1.9.0-beta01)