Skip to content

Instantly share code, notes, and snippets.

@NezSpencer
Created March 26, 2021 08:11
Show Gist options
  • Save NezSpencer/f9b62314e4be0a0fd6c011b47b13e7bc to your computer and use it in GitHub Desktop.
Save NezSpencer/f9b62314e4be0a0fd6c011b47b13e7bc to your computer and use it in GitHub Desktop.
Using the safeNavigate option to prevent the Navigation action not found issue
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
btn_open_screen_two.setOnClickListener {
findNavController().safeNavigate(FragmentOneDirections.actionFragmentOneToFragmentTwo())
}
btn_double_click.setOnClickListener {
performDoubleClick()
}
}
private fun performDoubleClick() {
for (i in 1 downTo 0) {
btn_open_screen_two.performClick()
}
}
fun NavController.safeNavigate(direction: NavDirections) {
Log.d(clickTag, "Click happened")
currentDestination?.getAction(direction.actionId)?.run {
Log.d(clickTag, "Click Propagated")
navigate(direction)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment