Modern navigation system and routing using Xamarin and ReactiveUI forms

Every year or so I have a mobile application and I choose Xamarin Forms for this. Before starting with an empty project, I’m trying to understand what frameworks and patterns are “trending”, and I’m trying to create something solid.

In my last application, my research led me to customize with Autofac for IoC and MvvmLight, as well as many other custom services that worked well with them.

When I came from the Internet, I did not run into the wave of Reactive Extensions, especially as an Angular developer. So this time, my setup is based on Splat (I prefer Autofac, but ... compromises , you know) and ReactiveUI.

I am very pleased with this. However, in my latest applications, there is still one thing that I'm really unhappy about: navigation. Most of the examples on the Internet are basic (push / pop on basic navigation pages), there are no libraries that do this well, and ReactiveUI navigation ... well, limited .

So, I had to make my own root browsing and navigation service, I mean that I did not write it, but Kent Boogaart did it in a blog post (if you are interested in answering my question, I suggest you take a look at imp, to better understand the limitations given in my use cases). And it looks good. And I liked this at first, before I had to handle more complex scripts, such as the login page, which leads to MasterDetailPageand TabbedPages.

, X.F Android , , . , , - , NavigationPage.

.

API, , Kent Boogaart.

:

public interface IView
{
    IObservable<IViewModel> PagePopped { get; }

    IObservable<Unit> PushPage(IViewModel pageViewModel, string contract, bool resetStack, bool animate);

    IObservable<Unit> PopPage(bool animate);

    IObservable<Unit> PushModal(IViewModel modalViewModel, string contract);

    IObservable<Unit> PopModal();
}

:

public interface IViewStackService
{
    IView View { get; }

    IObservable<IImmutableList<IViewModel>> PageStack { get; }

    IObservable<IImmutableList<IViewModel>> ModalStack { get; }

    IObservable<Unit> PushPage(
        IViewModel page,
        string contract = null,
        bool resetStack = false,
        bool animate = true);

    IObservable<Unit> PopPage(bool animate = true);

    IObservable<Unit> PushModal(IViewModel modal, string contract = null);

    IObservable<Unit> PopModal();
}

:

--------------------------
| navigation page        | <- user not logged in, it the root page
| --------- ------------ |
| | login | | register | |
| --------- ------------ |
|------------------------|
      |
      | -> user logs in
      |    via a hack, i can replace the root page with the masterdetails created by hand
      |    and reuse my previous root navigation page from the login screen as the new root,
      |    setting it as the Detail page (so the MasterDetail is not handled by my service)
      V
----------------------------------
| masterdetail page              |
| --------------------------     | -> this begins to get really complicated
| | detail 1 / tabbed page |     |
| | ---------- ----------  |     |
| | | page 1 | | page 2 |  |     |
| | ---------- ----------  |     |
| --------------------------     |
| ------------------------------ |
| | detail 2 / navigation page | | -> this could be doable with the current implementation
| | ----------  -------        | |    but erh..
| | | page 1 |->| etc |        | |
| | ----------  -------        | |
| ------------------------------ |
----------------------------------

, , , MasterDetailPages TabbedPages.

, : , ? ? ? , NuGet. , , , .

+4
2

MVVMV Framework Freshmvvm. "" . , . . IOC, . . , .

+1

github ReactiveUI, MasterDetailPage. , , , , .

0

Source: https://habr.com/ru/post/1688905/


All Articles