Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/escamoteur/reactiveui.dialogs
ReactiveUI wrapper for Acr.UserDialogs
https://github.com/escamoteur/reactiveui.dialogs
dialogs reactiveui
Last synced: 29 days ago
JSON representation
ReactiveUI wrapper for Acr.UserDialogs
- Host: GitHub
- URL: https://github.com/escamoteur/reactiveui.dialogs
- Owner: escamoteur
- License: mit
- Created: 2017-03-27T12:51:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-03-28T09:32:25.000Z (over 7 years ago)
- Last Synced: 2024-10-10T22:21:05.293Z (29 days ago)
- Topics: dialogs, reactiveui
- Language: C#
- Homepage:
- Size: 227 KB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ReactiveUI.Dialogs
Allan Ritchie's [Acr.UserDialogs](https://github.com/aritchie/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:
```c#
this.WhenAnyValue(x => x.ViewModel.Message)
.Where(message => !string.IsNullOrWhiteSpace(message))
.Subscribe(message =>
{
UserDialogs.Instance.Alert(message);
}
);
```or
```c#
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:
```c#
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:
```c#
public static IDisposable AlertWhen(this TSender This,
Expression> property, string title = null, string okText = null)public static IDisposable AlertWhen(this TSender This,
Expression> property, string title = null, string okText = null)public static IDisposable ToastWhen(this TSender This,
Expression> property, TimeSpan? dismissTimer = null)public static IDisposable ToastWhen(this TSender This,
Expression> property, TimeSpan? dismissTimer = null)// Disposing the returned Disposable ensures that the Spinner
// is hidden when the subscription is disposedpublic static LoadingDisposable ShowLoadingWhen(this TSender This,
Expression> property, string title = null, MaskType? maskType = null)public static LoadingDisposable ShowLoadingWhen(this TSender This,
Func> 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.