Created
April 20, 2020 01:46
-
-
Save furkanaskin/36123475e2a3b8c1c102bcce68a35204 to your computer and use it in GitHub Desktop.
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
open class BaseBottomTabFragment : Fragment() { | |
var isNavigated = false | |
fun navigateWithAction(action: NavDirections) { | |
isNavigated = true | |
findNavController().navigate(action) | |
} | |
fun navigate(resId: Int) { | |
isNavigated = true | |
findNavController().navigate(resId) | |
} | |
override fun onDestroyView() { | |
super.onDestroyView() | |
if (!isNavigated) | |
requireActivity().onBackPressedDispatcher.addCallback(this) { | |
val navController = findNavController() | |
if (navController.currentBackStackEntry?.destination?.id != null) { | |
findNavController().popBackStackAllInstances( | |
navController.currentBackStackEntry?.destination?.id!!, | |
true | |
) | |
} else | |
navController.popBackStack() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment