Как скрыть botomNavMenu?
Я пытался скрыть botomNavMenu двумя способами, и не один не получился:
Первый официальный:
navController.addOnDestinationChangedListener { controller, destination, arguments ->
when (destination.id) {
R.layout.fragment_login -> binding.bottomNavMenu.visibility = View.GONE
else -> binding.bottomNavMenu.visibility = View.VISIBLE
}
}
Второй я нашёл на англоязычном stackoverflow:
supportFragmentManager.registerFragmentLifecycleCallbacks(
object : FragmentManager.FragmentLifecycleCallbacks(){
override fun onFragmentViewCreated(
fm: FragmentManager,
f: Fragment,
v: View,
savedInstanceState: Bundle?
) {
TransitionManager.beginDelayedTransition(
binding.bottomNavMenu,
Slide(Gravity.BOTTOM).excludeTarget(R.id.nav_host, true)
)
when(f) {
is LoginFragment -> binding.bottomNavMenu.visibility = View.INVISIBLE
else -> binding.bottomNavMenu.visibility = View.VISIBLE
}
}
}, true
)
Оба в MainActivity в функции onCreate