Created
March 26, 2021 08:11
-
-
Save NezSpencer/f9b62314e4be0a0fd6c011b47b13e7bc to your computer and use it in GitHub Desktop.
Using the safeNavigate option to prevent the Navigation action not found issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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