Various problems occur when using nested NavHost
matsumo0922 opened this issue · comments
issue
This is a very puzzling bug. I am using PreCompose with the following structure, and I am trying to create a CoroutineScope inside Screen1 using rememberCoroutineScope
to operate DrawerState.
The following two problems have been identified.
- After transitioning to Screen2, the CoroutineScope is not re-created and remains Canceled.
- For some reason, drawerState cannot be operated at all.
I am still new to Android, so I am not sure of the cause, but I have confirmed that this only occurs when NavHost is nested. I am going to read the code and investigate the cause, but I have created an issue as soon as possible.
NavHost {
screen1 {
val scope = rememberCoroutineScope()
val drawerState = rememberDrawerState(DrawerValue.Closed)
ModalNavigationDrawer {
NavHost {
subScreen1 {
Button(
onClick = {
log(scope.isActive) // False if called again after returning from screen2
scope.launch {
drawerState.open() // Using another Active scope will not work after returning from Screen2.
}
}
)
}
subScreen2 {
...
}
}
}
}
screen2 {
...
}
}
versions
KMP Compose: 1.5.11
precompose 1.5.10
I've done some testing, this might be the inner scene's composable capture the wrong instance, rememberCoroutineScope
and rememberDrawerState
do return different instances every time when navigate back, but the inner scene still capture the old instance.
I'm working on a fix.
Could you release these changes?
There'll be a new release after I fix the ViewModel thread-safe issue.