mattinger
12/10/2021, 1:52 PMonDismissRequest
parameter. However, that seems to be missing from the navComponent.Ian Lake
12/10/2021, 7:28 PMDialog
2. The content that is hosted within the Dialog
Ian Lake
12/10/2021, 7:32 PMNavHost
is doing for you. Callbacks for when a destination is shown / popped should be looking at the NavController's state as the source of truth i.e.,
val navController = rememberNavController()
val currentBackStackEntry by navController.currentBackStackEntryAsState()
if (currentBackStackEntry != null) {
LaunchedEffect(logger, currentBackStackEntry) {
// Log whenever the current destination changes
logger.logCurrentScreen(currentBackStackEntry.destination.route)
}
}
Ian Lake
12/10/2021, 7:36 PMDialog
, AnimatedContent
, etc., you'd generally use a DisposableEffect
and specifically its onDispose
to tell when that content goes out of scope - i.e., your dialog is no longer visible.
dialog("dialogRoute") { backStackEntry ->
// This is the content within the Dialog
DisposableEffect(logger) {
logger.logScreenVisible(backStackEntry.destination.route)
onDispose {
logger.logScreenDismised(backStackEntry.destination.route)
}
}
}