class: title, smokescreen, shelf, no-footer background-image: url(/assets/images/presentations/meetup-home-slide.jpg) # Dynamic navigation ### A feedback on a real application --- layout: true .footer[ - @johnthiriet - ![logo](/assets/images/presentations/meetup-crossplatform-in-paris.jpg) ] --- # What is navigation ? Navigation is the process of going from one screen to another. Every platform has its own way to define screens and to perform a transition between them. | Platform | Screen | Navigation technique | |----------------|--------------------------------------|------------------------------------| | iOS | ViewController or Xibs or Storyboard | Segues or ViewController's methods | | Android | Activity or Fragment | Intents or FragmentManager | | Xamarin.Forms | Page | INavigation framework service | --- class: center ![](https://johnthiriet.com/assets/images/presentations/meetup-dynamic-navigation-navigation-patterns.png# maxw-80pct center) Here are several example of well known navigation paradigms. --- class: center ![](https://johnthiriet.com/assets/images/presentations/meetup-dynamic-navigation-xcode.png# maxw-80pct center) XCode storyboards --- layout: false # Predictible navigation vs Dynamic navigation In the storyboard case earlier we were looking at a perfectly predictible navigation. We know which screen links to another one and how the navigation happens between them. Such a process is fine but falls shorts when the navigation flow between screens is unknown at compile time. Here, we need an *__abstraction__*. --- layout: false class: compact # Welcome to the navigation service This class exposes navigation paradigms and abstracts native techniques. ``` public interface INavigationService { Task
NavigateToAsync(string sourceKey, string destinationKey, object parameter = null); Task
NavigateNextAsync(string sourceKey, object parameter = null); Task
DismissModalAsync(string sourceKey, string destinationKey, object result = null); Task NavigateToMainViewAsync(CancellationToken cancellationToken, object parameter = null); ... } ``` --- class: center ![](https://johnthiriet.com/assets/images/presentations/meetup-home-slide.jpg# maxw-80pct center) Demo Xamarin.Forms - The dynamic wizard --- layout: false class: compact # Going native with the presenter This class abstracts native navigation techniques and links a logical screen to a native screen. I.e. You want to go to account creation screen, you will get to the `AccountCreationActivity`. ``` public interface IPresenter { IPresenterNode Create(string presenterKey); IPresenterNode CreateRoot(string presenterKey); IPresenterNode CreateDismiss(string presenterKey); IPresenterNode CreateModal(string presenterKey); IPresenterNode CreateTab(IPresenterNodeParameter presenterNodeParameter); IPresenterNode CreateRootTab(string presenterKey, IPresenterNodeParameter presenterNodeParameter); } ``` --- layout: false class: compact # Presenter - Implementation ``` public class AndroidPresenter : IPresenter { public IPresenterNode Create(string presenterKey) { return new AndroidShowNodePresenter(presenterKey); } public IPresenterNode CreateRoot(string presenterKey) { return new AndroidShowRootNodePresenter(presenterKey); } public IPresenterNode CreateDismiss(string presenterKey) { return new AndroidDismissNodePresenter(presenterKey); } ... } ``` --- layout: false class: compact # Presenter - Node implementation ``` public class AndroidShowNodePresenter : IPresenterNode { ... public virtual Task RunNodeAsync(object parameter = null) { var activityType = GetStartActivityType(PresenterKey); var intent = CreateStartActivityIntent(activityType); if (intent != null) { AddIntentFlags(intent); return CurrentActivity.StartActivityAsync(activityType, intent, parameter); } return Task.CompletedTask; } ... } ``` --- layout: false class: roomy # Recap - There are some cases where the navigation flow is only know at runtime. - To handle these cases, an abstraction needs to be made in the form of a navigation service. - Its implementation depends on the technology used be the concept is valid everywhere. - In the case of a Xamarin Native application the concept of a presenter needs to be added. - Provided that your implementation is flexible enough you could even have a navigation configurable with distant configuration files. --- # Thank you .qrcode.db.fr.w-40pct.ml-4[] These slides are available on [https://johnthiriet.com](https://johnthiriet.com/presentations/meetup-dynamic-navigation) or by scanning the QR code. Contact : @johnthiriet - [Twitter: @JohnThiriet](https://twitter.com/JohnThiriet) - [LinkedIn: @JohnThiriet](https://linkedin.com/in/JohnThiriet)