• Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 6 years ago
  • Updated 29 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A ReactiveUI navigation library for Xamarin.Forms

Sextant

NuGet Stats Build Code Coverage

Sextant

A ReactiveUI view model based navigation library

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.

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 CoreBadge
Xamarin.Forms Sextant.XamForms XamBadge
Xamarin.Forms Sextant.Plugins.Popup PopupBadge
Xamarin.iOS Sextant CoreBadge
Avalonia Sextant.Avalonia CoreBadge

Target Platform Versions

Verify you have the minimum version 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.

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:

Locator
    .Current
    .GetService<IParameterViewStackService>()
    .PushPage<PassViewModel>()
    .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:

/// <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);

Example

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<FirstModalViewModel>(),
                outputScheduler: RxApp.MainThreadScheduler);
    }

    public ReactiveCommand<Unit, Unit> OpenModal { get; }
}

Pass Parameters

Version 2.0 added support for passing parameters when navigating.

Example

public class ViewModel
{
    private readonly IParameterViewStackServicen _viewStackService;

    public ViewModel(IParameterViewStackServicen viewStackService)
    {
        _viewStackService = viewStackService;

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

    public ReactiveCommand<Unit, Unit> 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.

public class NavigableViewModel : INavigable
{
        public string? _parameter;

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

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

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

Samples

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:

More Repositories

1

refit

The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
C#
8,590
star
2

ReactiveUI

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
C#
8,080
star
3

Akavache

An asynchronous, persistent key-value store created for writing desktop and mobile applications, based on SQLite3. Akavache is great for both storing important data as well as cached local data that expires.
C#
2,448
star
4

splat

Makes things cross-platform
C#
972
star
5

Camelotia

Cross-platform sample .NET GUI for cloud file management.
C#
556
star
6

ReactiveUI.Samples

This repository contains ReactiveUI samples.
C#
329
star
7

Fusillade

An opinionated HTTP library for Mobile Development
C#
310
star
8

punchclock

Make sure your asynchronous operations show up to work on time
C#
261
star
9

Pharmacist

Builds observables from events.
C#
240
star
10

ReactiveUI.Validation

Validation helpers for ReactiveUI-based apps.
C#
238
star
11

ReactiveMvvm

Cross-platform ReactiveUI sample app built for a talk at MSK .NET conf.
C#
180
star
12

website

ReactiveUI documentation and guidelines website. PR's welcome! πŸ’–
C#
35
star
13

Splat.DI.SourceGenerator

C#
30
star
14

ReactiveUI.SourceGenerators

Use source generators to generate objects.
C#
27
star
15

Reactive.Wasm

A Web Assembly versions of the System.Reactive classes.
C#
13
star
16

ReactiveObject.Generators

C#
8
star
17

rfcs

RFCs for changes to ReactiveUI
Shell
5
star
18

styleguide

design / marketing style guide for ReactiveUI
HTML
4
star
19

Maui.Plugins.Popup

ReactiveUI support for Maui Popups
C#
4
star
20

.github

2
star
21

actions-common

Common GitHub actions for the ReactiveUI project
2
star
22

ReactiveUI.Uno

C#
1
star