0

I want to check the actual Fragment if it's dirty and warn the user to lose his changes. I could'nt find an Listener on the Navcontroller to interact before the navigation happens.

I already tried to set a listener to the BottomNavigationView but the result was that the Navigation does'nt work anymore after the reset.

requireActivity().bottomNavigationView.setOnNavigationItemSelectedListener{menuItem ->
            DialogUtil.showBeforeLeaveDetailFragmentDialog(context!!){
                requireActivity().bottomNavigationView.setOnNavigationItemSelectedListener(null)
                findNavController().navigate(menuItem.itemId)
            }
            false
        }

Is there any global Listener which i can use or another clean solution?

Bambl
  • 1

1 Answers1

0

This should work.

requireActivity().bottomNavigationView.setOnNavigationItemSelectedListener{menuItem ->
            DialogUtil.showBeforeLeaveDetailFragmentDialog(context!!){
                return NavigationUI.onNavDestinationSelected(it, navController)
            }
            false
        }

And I don't know why are you clearing the NavigationItemSelectedListener. Explain why you are doing it.