Only navigate when not on the current screen

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-10-29 17:09:27 +05:30
parent 97dc62afe1
commit b031d36fa2
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -71,12 +71,11 @@ fun LobstersApp(
label = { Text(stringResource(id = screen.labelRes)) },
selected = currentRoute == screen.route,
onClick = {
// This is the equivalent to popUpTo the start destination
navController.popBackStack(navController.graph.startDestination, false)
// This if check gives us a "singleTop" behavior where we do not create a
// second instance of the composable if we are already on that destination
if (currentRoute != screen.route) {
// This is the equivalent to popUpTo the start destination
navController.popBackStack(navController.graph.startDestination, false)
navController.navigate(screen.route)
}
}