Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android navigation component bottomnavigationview intercept click

I have a bottomnavigationview which is linked with navigation component using setupWithNavController(). It works as you would expect, pressing on the menu item will move me to a required window.

The problem is, that before redirecting to a different screen, I need to check if user is logged in or not and depending on that, I would need to redirect to a different screen.

So far it seems that I can use setOnNavigationItemSelectedListener() on my bottomnavigationview, but then I loose all the convenience of setupWithNavController() as then I have to manually specify all the destinations I want to go.

Are there any better ways to implement this?

Edit: My login screen is actually transparent so, going to required fragment and then showing login screen on top might be tricky

like image 932
SMGhost Avatar asked May 13 '26 12:05

SMGhost


1 Answers

bottomNav.setOnNavigationItemSelectedListener {
            if (//not login) {
                //to login fragment
                false
            } else {
                NavigationUI.onNavDestinationSelected(it, homeController)
            }
        }
like image 107
sankemao Avatar answered May 15 '26 02:05

sankemao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!