Giter Site home page Giter Site logo

reactiveui.dialogs's Introduction

ReactiveUI.Dialogs

Allan Ritchie's Acr.UserDialogs is an amazing libary that make live for any mobile devloper much easier when it comes to Alerts, Toasts or Spinners.

One of it big advantages is that you can call it from almost anywhere in your code. This can be in at the same time problematic because it misleads to violate the separation of View and ViewModel.

Another problem that can occur if you call it to the wrong time in the App lifecycle on Android is that you get an ugly exception.

While moving the Dialog code to my View and using RxUI I could solve both problems by writing:

this.WhenAnyValue(x => x.ViewModel.Message)
    .Where(message => !string.IsNullOrWhiteSpace(message))
    .Subscribe(message =>
        {
            UserDialogs.Instance.Alert(message);
            }
    );

or

ViewModel.GetReplay.IsExecuting.Subscribe(busy =>
    {
        if (busy)
        {
            UserDialogs.Instance.ShowLoading();
        }
        else
        {
            UserDialogs.Instance.HideLoading();
            }

        });

So I deciced to start writing an ReactiveUI wrapper around Acr.UserDialogs. So that I now can write:

this.AlertWhen(x => x.ViewModel.AlertMessage).DisposeWith(d);
this.ToastWhen(x => x.ViewModel.ToastMessage).DisposeWith(d);

this.ViewModel.ShowLoadingWhen(x=>x.ShowSpinner.IsExecuting).DisposeWith(d);

As soon as the observed string properties get a value assigned a Dialog/Toast is shown

Opening a new Dialog outmatically closes any currently open ones.

Before an Dialog is shown it is checked if the App is not backgrounded (Not sure yes if it would make sense to throw an optional Exception here)

Currently I support this methods:

public static IDisposable AlertWhen<TSender>(this TSender This,
  Expression<Func<TSender, string>> property, string title = null, string okText = null)

public static IDisposable AlertWhen<TSender>(this TSender This,
    Expression<Func<TSender, AlertConfig>> property, string title = null, string okText = null)


public static IDisposable ToastWhen<TSender>(this TSender This,
    Expression<Func<TSender, string>> property, TimeSpan? dismissTimer = null)

public static IDisposable ToastWhen<TSender>(this TSender This,
    Expression<Func<TSender, ToastConfig>> property, TimeSpan? dismissTimer = null)


// Disposing the returned Disposable ensures that the Spinner 
// is hidden when the subscription is disposed

public static LoadingDisposable ShowLoadingWhen<TSender>(this TSender This,
    Expression<Func<TSender, bool>> property, string title = null, MaskType? maskType = null)


public static LoadingDisposable ShowLoadingWhen<TSender>(this TSender This,
    Func<TSender,IObservable<bool>> busy, string title = null, MaskType? maskType = null)

Nuget

Install-Package ReactiveUI.Dialogs

Important:

Make sure to add the NUget to your Platform project too Call the UserDialogs Init method in your MainActivity on Android

UserDialogs.Init(this)

Contribution

any PRs to complete this wrapper are very welcome.

reactiveui.dialogs's People

Contributors

escamoteur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.