Separate Navigation Stacks (Day 5)

Complex page workflows can become a burden unless you separate the workflows into different stacks. The most common page workflow you will encounter is the Authentication and Main App workflow. Why do we separate these? The authentication workflow (the login page or register page) shouldn’t be accessible from the main application and the main application shouldn’t be accessible from the authentication pages.

PageFlow

When doing the login stack, they are recommendations to use the ModalStack for this. Xamarin Forms has 2 types of navigation stacks in a navigation page. Navigation and Modal. There is nothing different about them except they are completely separate navigation stacks within the same NavigationPage. However I never recommend this approach due to the page flickering issue and this depends on which way you load your pages.

So when you load a page the Main screen shows first, then quickly loads the (Modal) Login screen and you see that page flicker. Its not a nice feel to the app.

Multiple NavigationPages

If you run separate NavigationPage’s you don’t have that issue. You can pre load any navigation pages in the background and only show the applicable NavigationPage at any time. The added benefit is you can be deep in one NavigationPage, switch to another, then jump right back in to where you left off with this approach. You can then even jump right back into the other workflow.

Create a Stack

I call these Stacks in my setup and they are a contained way to setup a Navigation Stack. In the stacks you

  1. Map Key’s to Pages (for the navigation service)
  2. Map ViewModels to Pages (for binding to pages)
  3. Starting Page
  4. Initialize the Navigation Page (and/or MasterDetailPage if applicable)
All of this can be seen in my MainStack.cs example.
The stack is then loaded in InitializeStacks() and you can switch stack by calling the LoadStack() method in AppLoader.cs. It allows you to switch between stacks at any point in the application. The state of each stack is kept as you switch between them.

 

<< The ViewModel (Day 4) || Models and Service Layer (Day 6) >>

14 Days To Building An Enteprise Quality Xamarin Forms App

Microsoft MVP (Xamarin) | Exrin | Xamarin Forms Developer | Melbourne, Australia | Open to sponsorship to Canada or US

Related Posts

Leave A Comment?