Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android navigation component- With Login screens

When dealing with login screens, I am trying to work out the better approach - either execute navigation "action" to go to login fragment on first use (and hide back button to actual app), or start a new login activity (with its own nav graph). For the first approach (just using navigation components), I do not know the way to remove the back button without a hack "hide". I tried using navoptions, setpopupto etc., but it does not work. Code below:

val navOptions = NavOptions.Builder()
                .setPopUpTo(R.id.home_fragment, true)
                .build()

host?.navController?.navigate(R.id.action_global_signUpFragment_dest, null, navOptions)

Two questions then: 1) How to properly handle login transition with just navigation component? 2) Is starting a new login activity, with separate nav graph, a better idea?

like image 337
Rowan Gontier Avatar asked Nov 28 '18 22:11

Rowan Gontier


1 Answers

I think the first approach is better. To hide the 'back' button on your toolbar inside signUpFragment you can use AppBarConfiguration, and customize which destinations are considered top-level destinations. For example:

val appBarConfiguration = AppBarConfiguration.Builder(setOf(R.id.home_fragment, R.id.signUpFragment_dest)).build()
NavigationUI.setupWithNavController(toolbar, navController, appBarConfiguration)

This way home_fragment and signUpFragment_dest will be considered top-level destinations, and won't have back button on toolbar.

like image 180
Alex Avatar answered Oct 24 '22 08:10

Alex