Sextant was born from a fork of Xamvvm which is nice and simple MVVM Framework with a good navigation system. The problem is, I just wanted a simple navigation system to use with ReactiveUI without all the things that come along an MVVM framework. Plus, I wanted to make it more "Reactive Friendly".
Then a wild Rodney Littles appears, and with him an implementation of this AMAZING POST by Kent
Sextant is in a very initial stage and in constant change, so please be pantience with use... because we will break things.
This library is nothing more than me "standing on the shoulders of giants": Kent for been the original and true creator of this, I pretty much just copied and pasted it :) Geoffrey Huntley maintainer on ReactiveUI.
Install the nuget package on your Forms project and ViewModels project.
Pre release packages are available at https://nuget.pkg.github.com/reactiveui/index.json
Platform | Sextant Package | NuGet |
---|---|---|
UWP | Sextant | |
Xamarin.Forms | Sextant.XamForms | |
Xamarin.iOS | Sextant |
Verify you have the minimum version for your target platform (i.e. Android, iOS, Tizen).
Version 2.0 added new extensions methods for the IMutableDepedencyResolver
that allow you to register an IViewFor
to a View Model.
Locator
.CurrentMutable
.RegisterNavigationView(() => new NavigationView(RxApp.MainThreadScheduler, RxApp.TaskpoolScheduler, ViewLocator.Current))
.RegisterParameterViewStackService()
.RegisterView<RedPage, RedViewModel>()
.RegisterView<FirstPage, FirstViewModel>();
Set the initial page:
Locator
.Current
.GetService<IParameterViewStackService>()
.PushPage(new PassViewModel(), null, true, false)
.Subscribe();
MainPage = Locator.Current.GetNavigationView("NavigationView");
After that all you have to do is call one of the methods inside your ViewModels:
/// <summary>
/// Pops the <see cref="IPageViewModel"/> off the stack.
/// </summary>
/// <param name="animate">if set to <c>true</c> [animate].</param>
/// <returns></returns>
IObservable<Unit> PopModal(bool animate = true);
/// <summary>
/// Pops the <see cref="IPageViewModel"/> off the stack.
/// </summary>
/// <param name="animate">if set to <c>true</c> [animate].</param>
/// <returns></returns>
IObservable<Unit> PopPage(bool animate = true);
/// <summary>
/// Pushes the <see cref="IPageViewModel"/> onto the stack.
/// </summary>
/// <param name="modal">The modal.</param>
/// <param name="contract">The contract.</param>
/// <returns></returns>
IObservable<Unit> PushModal(IPageViewModel modal, string contract = null);
/// <summary>
/// Pushes the <see cref="IPageViewModel"/> onto the stack.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="contract">The contract.</param>
/// <param name="resetStack">if set to <c>true</c> [reset stack].</param>
/// <param name="animate">if set to <c>true</c> [animate].</param>
/// <returns></returns>
IObservable<Unit> PushPage(IPageViewModel page, string contract = null, bool resetStack = false, bool animate = true);
OpenModal = ReactiveCommand
.CreateFromObservable(() =>
this.ViewStackService.PushModal(new FirstModalViewModel(ViewStackService)),
outputScheduler: RxApp.MainThreadScheduler);
Version 2.0 added support for passing parameters when navigating.
Navigate = ReactiveCommand.CreateFromObservable(
() => navigationService
.PushPage(new NavigableViewModel(), new NavigationParameter { { "parameter", parameter } }),
outputScheduler: RxApp.MainThreadScheduler);
The INavigable
interface exposes view model lifecycle methods that can be subscribed to. These methods unbox your parameter object. Implementing the interface allows you to assign values to the View Model during Navigation.
Sextant is developed under an OSI-approved open source license, making it freely usable and distributable, even for commercial use. We ❤ the people who are involved in this project, and we’d love to have you on board, especially if you are just getting started or have never contributed to open-source before.
So here's to you, lovely person who wants to join us — this is how you can support us:
- Responding to questions on StackOverflow
- Passing on knowledge and teaching the next generation of developers
- Submitting documentation updates where you see fit or lacking.
- Making contributions to the code base.