Skip to content

Instantly share code, notes, and snippets.

@NezSpencer
Created March 26, 2021 07:33
Show Gist options
  • Save NezSpencer/b58036600322b4188997c2b130ba47d3 to your computer and use it in GitHub Desktop.
Save NezSpencer/b58036600322b4188997c2b130ba47d3 to your computer and use it in GitHub Desktop.
SafeNavigate extension methods
fun NavController.safeNavigate(direction: NavDirections) {
currentDestination?.getAction(direction.actionId)?.run { navigate(direction) }
}
fun NavController.safeNavigate(
@IdRes currentDestinationId: Int,
@IdRes id: Int,
args: Bundle? = null
) {
if (currentDestinationId == currentDestination?.id) {
navigate(id, args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment