Signup Flow With Advanced Navigation Example
I am currently using bottom navigation like in navigation advanced example, I am trying direct user to signup flow if user is not authenticated. I use following code in side defaultly selected fragment to direct user to sign up flow (login_nav_graph) if they are not authenticated.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if(!authenticated){
view.findNavController().navigate(R.id.action_frag1Fragment_to_login_nav_graph)
}
}
But there are few problems
- Shows back button when user in signup flow
- Bottom navigation is shown in signup flow
These problems make sense, Reasons:
- since signup flow (
login_nav_graph
) is nested inside bottom navs first items(defaultly selected) navigation graph. - Bottom nav is on
activity_main
layout.
So how could I integrate signup flow into navigation advanced example and overcome above mentioned issues with a better approach?
Note:
code is very similar to navigation advanced example, I introduced separate nav graph for signup flow called login_nav_graph
and above mentioned code in defautly selected fragment
Answer
Fixed the issue by doing following.
- Add
login_nav_graph
to the nav graph which contains defaultly selected fragment as a nested nav graph. Create an
action/path
from defaultly selected fragment (frag1Fragment
) to thelogin_nav_graph
and set thePop To
behavior of the action to thefrag1Fragment
's nav graph.Create following two methods inside the
MainActivity
in order to toggle the visibility of the action bar and bottom nav.fun toggleBottomNavVisibility(){ if(bottom_nav.visibility == View.VISIBLE){ bottom_nav.visibility = View.GONE }else{ bottom_nav.visibility = View.VISIBLE } }
...
fun toggleActionBarVisibility(){
if(supportActionBar!!.isShowing){
supportActionBar?.hide()
}
else{
supportActionBar?.show()
}
}
- Update the
onViewCreated
method of thefrag1Fragment
as follows
...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if(!authenticated){
// hide bottom navigation and action bar
val activity = activity as MainActivity
activity.toggleBottomNavVisibility()
activity.toggleActionBarVisibility()
findNavController().navigate(R.id.action_frag1Fragment_to_login_nav_graph)
}
}
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View