Afzal Najam
12/18/2020, 6:11 AMrobnik
12/18/2020, 11:51 AMAfzal Najam
12/19/2020, 2:53 AMuserAuthenticated
becomes false, can I navigate to screen A immediately?robnik
12/19/2020, 9:18 PMAfzal Najam
12/19/2020, 9:39 PM/**
* If not authenticated, navigate to Password screen.
* [MainActivity.onBackPressed] controls closing the app
* when back button is pressed.
* When authenticated, if the user wasn't already in the app,
* show the Home screen, otherwise pop the backstack to resume
* what the user was doing.
*/
val authenticated by authVm.authState.observeAsState(initial = AuthState.Unauthenticated)
onCommit(authenticated) {
Timber.d("Authenticated: $authenticated")
if (authenticated != AuthState.Authenticated) {
navController.navigate(Screen.Password.route) {
launchSingleTop = true
}
} else {
if (navController.previousBackStackEntry == null) {
navController.navigate(Screen.Home.route) {
popUpTo(Screen.Password.route) {
inclusive = true
}
}
} else {
navController.popBackStack()
}
}
}