|
private fun View.goTo( |
|
@IdRes id: Int, bundle: Bundle? = null, navOptions: NavOptions? = null, |
|
navigatorExtras: Navigator.Extras? = null |
|
) { |
|
if (mayNavigate(id)) findNavController().navigate(id, bundle, navOptions, navigatorExtras) |
|
} |
|
|
|
private fun Fragment.goTo( |
|
@IdRes id: Int, bundle: Bundle? = null, navOptions: NavOptions? = null, |
|
navigatorExtras: Navigator.Extras? = null |
|
) { |
|
if (mayNavigate(id)) findNavController().navigate(id, bundle, navOptions, navigatorExtras) |
|
} |
|
|
|
private fun Fragment.mayNavigate(@IdRes id: Int): Boolean { |
|
val navController = this.findNavController() |
|
val destinationIdInNavController = navController.currentDestination?.id |
|
val destinationIdOfThisFragment = view?.getTag(id) ?: destinationIdInNavController |
|
|
|
return if (destinationIdInNavController == destinationIdOfThisFragment) { |
|
view?.setTag(id, destinationIdOfThisFragment) |
|
true |
|
} else { |
|
logDebug { "May not navigate: current destination is not the current fragment." } |
|
false |
|
} |
|
} |
|
|
|
private fun View.mayNavigate(@IdRes id: Int): Boolean { |
|
val navController = this.findNavController() |
|
val destinationIdInNavController = navController.currentDestination?.id |
|
val destinationIdOfThisFragment = getTag(id) ?: destinationIdInNavController |
|
|
|
return if (destinationIdInNavController == destinationIdOfThisFragment) { |
|
setTag(id, destinationIdOfThisFragment) |
|
true |
|
} else { |
|
logDebug { "May not navigate: current destination is not the current fragment." } |
|
false |
|
} |
|
} |