Skip to content

Instantly share code, notes, and snippets.

@TorkelV
Last active September 3, 2021 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TorkelV/736ee59d3dd4e5adefd86547c3fc5942 to your computer and use it in GitHub Desktop.
Save TorkelV/736ee59d3dd4e5adefd86547c3fc5942 to your computer and use it in GitHub Desktop.
fun Fragment.navigate(directions: NavDirections) {
val controller = findNavController()
val currentDestination = (controller.currentDestination as? FragmentNavigator.Destination)?.className
?: (controller.currentDestination as? DialogFragmentNavigator.Destination)?.className
if (currentDestination == this.javaClass.name) {
controller.navigate(directions)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment