Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Component with Login / Register / Home flow

Tags:

android

kotlin

I would like to use the new Navigation Component for my next application but I can't quite wrap my head around the overall flow of navigation. The Android team recommends a single activity as an entry point. They also suggest that conditional elements like a login / register should not be the entry point. But then how do you display the login and register buttons if the entry screen is supposed to be the home screen?

Another idea is to use a Splash screen, have the logic there to determine if the user is already logged in, if so go to the home screen, if not show the login / register screen(s).

My other issue is with the single activity. My home screen would need to be a screen with a Bottom Navigation.

How do you tie all of this the "right way"? Do I need to have a separate navigation graph for the Home view, with the Bottom Navigation and the many screens that will flow from there?

All the examples I have found have been very straightforward, and the few I have seen with a Splash screen splitting into Home and Login have a very simple Home fragment, which in my case would be . more complex with the Bottom Nav.

Thanks.

like image 921
EscapeArtist Avatar asked Feb 06 '19 06:02

EscapeArtist


People also ask

How can navigation component be used in activity?

Create a navigation graph To add the graph, right-click on this directory, and choose New > Navigation resource file. The Navigation component uses an activity as a host for navigation and swaps individual fragments into that host as your users navigate through your app.

What is popUpToInclusive?

When navigating back to destination A, we also popUpTo A, which means that we remove B and C from the stack while navigating. With app:popUpToInclusive="true" , we also pop that first A off of the stack, effectively clearing it.


1 Answers

One way to do this, you hide the bottom navigation in the login and popup the homepage when you navigate to the login page so the user would not be able to go back to the splash screen

1-you can hide the bottom naviagtion bar in the login fragment like this

val toolbar = activity!!.findViewById<Toolbar>(R.id.toolbar)
val bottombar = activity!!.findViewById<BottomNavigationView>(R.id.bottomNavigationView)
        toolbar.visibility = View.GONE
        bottombar.visibility = View.GONE

2- popup the splash fragment when you navigate to the login page

<action
            android:id="@+id/action_splashFragment_to_loginFragment"
            app:destination="@id/loginFragment"
            app:popUpTo="@+id/splashFragment"
            app:popUpToInclusive="true"/>

Hopefully it will work for you

like image 178
max man Avatar answered Oct 20 '22 07:10

max man