Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/reactiveui/sextant

A ReactiveUI navigation library for Xamarin.Forms
https://github.com/reactiveui/sextant

hacktoberfest mvvm-framework navigation reactiveui reactiveui-navigation-library sextant xamarin

Last synced: 6 days ago
JSON representation

A ReactiveUI navigation library for Xamarin.Forms

Awesome Lists containing this project

README

        

## Sextant

[![NuGet Stats](https://img.shields.io/nuget/v/sextant.svg)](https://www.nuget.org/packages/sextant) ![Build](https://github.com/reactiveui/Sextant/workflows/Build/badge.svg) [![Code Coverage](https://codecov.io/gh/reactiveui/sextant/branch/main/graph/badge.svg)](https://codecov.io/gh/reactiveui/sextant)
[![](https://img.shields.io/nuget/dt/sextant.svg) ](https://www.nuget.org/packages/sextant) [![](https://img.shields.io/badge/chat-slack-blue.svg)](https://reactiveui.net/slack)

Sextant

## A ReactiveUI view model based navigation library

Sextant was born from a fork of [Xamvvm](https://github.com/xamvvm/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](https://github.com/reactiveui/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](https://github.com/rlittlesii) appears, and with him an implementation of this [AMAZING POST](https://kent-boogaart.com/blog/custom-routing-in-reactiveui) by [Kent](https://github.com/kentcb)

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](https://github.com/kentcb) for been the original and true creator of this, I pretty much just copied and pasted it :)
[Geoffrey Huntley](https://github.com/ghuntley) maintainer on [ReactiveUI](https://github.com/reactiveui/ReactiveUI).

## NuGet Installation

Install the nuget package on your Forms project and ViewModels project.

### GitHub
Pre release packages are available at https://nuget.pkg.github.com/reactiveui/index.json

### NuGet

| Platform | Sextant Package | NuGet |
| ----------------- | -------------------------------- | ------------------------ |
| UWP | [Sextant][UwpDoc] | [![CoreBadge]][Core] |
| Xamarin.Forms | [Sextant.XamForms][XamDoc] | [![XamBadge]][Xam] |
| Xamarin.Forms | [Sextant.Plugins.Popup][XamDoc] | [![PopupBadge]][Popup] |
| Xamarin.iOS | [Sextant][IosDoc] | [![CoreBadge]][Core] |
| Avalonia | [Sextant.Avalonia][AvaloniaDoc] | [![CoreBadge]][Avalonia] |

[Core]: https://www.nuget.org/packages/Sextant/
[CoreBadge]: https://img.shields.io/nuget/v/Sextant.svg
[CoreDoc]: https://reactiveui.net/docs/getting-started/installation/
[IosDoc]: https://reactiveui.net/docs/getting-started/installation/xamarin-ios
[UwpDoc]: https://reactiveui.net/docs/getting-started/installation/universal-windows-platform
[AvaloniaDoc]: https://www.reactiveui.net/docs/getting-started/installation/avalonia

[Xam]: https://www.nuget.org/packages/Sextant.XamForms/
[XamBadge]: https://img.shields.io/nuget/v/Sextant.XamForms.svg
[Popup]: https://www.nuget.org/packages/Sextant.Plugins.Popup/
[PopupBadge]: https://img.shields.io/nuget/v/Sextant.Plugins.Popup.svg
[XamDoc]: https://reactiveui.net/docs/getting-started/installation/xamarin-forms
[Avalonia]: https://www.nuget.org/packages/Sextant.Avalonia/

### Target Platform Versions

##### Verify you have the [minimum version](https://reactiveui.net/docs/getting-started/minimum-versions#platform-minimums) for your target platform (i.e. Android, iOS, Tizen).

## Register Components

### Views

Version 2.0 added new extensions methods for the `IMutableDepedencyResolver` that allow you to register an `IViewFor` to a View Model.

```csharp
Locator
.CurrentMutable
.RegisterNavigationView(() => new NavigationView(RxApp.MainThreadScheduler, RxApp.TaskpoolScheduler, ViewLocator.Current))
.RegisterParameterViewStackService()
.RegisterViewForNavigation(() => new PassPage(), () => new PassViewModel())
.RegisterViewForNavigation(() => new ReceivedPage(), () => new ReceivedViewModel());
```

Set the initial page:
```csharp
Locator
.Current
.GetService()
.PushPage()
.Subscribe();

MainPage = Locator.Current.GetNavigationView("NavigationView");
```

## Use the Navigation Service

After that all you have to do is call one of the methods inside your ViewModels:
```csharp
///
/// Pops the off the stack.
///
/// if set to true [animate].
///
IObservable PopModal(bool animate = true);

///
/// Pops the off the stack.
///
/// if set to true [animate].
///
IObservable PopPage(bool animate = true);

///
/// Pushes the onto the stack.
///
/// The modal.
/// The contract.
///
IObservable PushModal(IPageViewModel modal, string contract = null);

///
/// Pushes the onto the stack.
///
/// The page.
/// The contract.
/// if set to true [reset stack].
/// if set to true [animate].
///
IObservable PushPage(IPageViewModel page, string contract = null, bool resetStack = false, bool animate = true);
```

### Example
```csharp
public class ViewModel
{
private readonly IViewStackServicen _viewStackService; // or IParameterViewStackServicen

public ViewModel(IViewStackServicen viewStackService)
{
_viewStackService = viewStackService;

OpenModal = ReactiveCommand
// FirstModalViewModel must implement IViewModel or INavigable
.CreateFromObservable(() => viewStackService.PushModal(),
outputScheduler: RxApp.MainThreadScheduler);
}

public ReactiveCommand OpenModal { get; }
}
```

## Pass Parameters

Version 2.0 added support for passing parameters when navigating.

### Example

```csharp
public class ViewModel
{
private readonly IParameterViewStackServicen _viewStackService;

public ViewModel(IParameterViewStackServicen viewStackService)
{
_viewStackService = viewStackService;

Navigate = ReactiveCommand
// NavigableViewModel must implement INavigable
.CreateFromObservable(() => viewStackService.PushModal(new NavigationParameter { { "parameter", parameter } }),
outputScheduler: RxApp.MainThreadScheduler);
}

public ReactiveCommand Navigate { get; }
}
```

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.

```csharp
public class NavigableViewModel : INavigable
{
public string? _parameter;

public IObservable WhenNavigatedFrom(INavigationParameter parameter)
{
return Observable.Return(Unit.Default)
}

public IObservable WhenNavigatedTo(INavigationParameter parameter)
{
parameter.TryGetValue("parameter", out _parameter);
return Observable.Return(Unit.Default);
}

public IObservable WhenNavigatingTo(INavigationParameter parameter)
{
return Observable.Return(Unit.Default);
}
}
```

## Samples

- [Sample](https://github.com/reactiveui/Sextant/tree/main/Sample)
- [Navigation Parameter Sample](https://github.com/reactiveui/ReactiveUI.Samples/tree/main/xamarin-forms/Navigation.Parameters)

## Contribute

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](https://stackoverflow.com/questions/tagged/sextant)
* [Passing on knowledge and teaching the next generation of developers](http://ericsink.com/entries/dont_use_rxui.html)
* Submitting documentation updates where you see fit or lacking.
* Making contributions to the code base.