DEV Community

Kamu
Kamu

Posted on

Introduction of AiForms.Dialogs for Xamarin.Forms

Speaking of Dialogs in Xamarin.Forms, ACR User Dialogs is very famous, and I have used a lot in business.
In personal development, I used not it but self-implemented using DependencyService. And I implemented such as a loading dialog with it.
On Android, I used a ProgressDialog, and this turned to Deprecated, so I thought refactoring it.
When I was refactoring it, I hit on "This can be independent as a Library by a little effort".
Although it wasn't a little effort as a result, I almost finished it and so I released this as a NuGet package.

First of all, I thought that I wanted to replace self-implemented to ACR User Dialogs. But its GitHub repository is not active and it is not customizable such as replacing a loading icon. So I thought that I should make a library myself.

While implementing it, I found Popup Page Plugin at my twitter timeline. I thought this library was just what I wanted. But because I had already implemented most of it then, I decided to complete it differentiating from Popup Page Plugin.

Repository

Source

https://github.com/muak/AiForms.Dialogs

Nuget

https://www.nuget.org/packages/AiForms.Dialogs/

This is currently a pre-release.

Demo

Summary

AiForms.Dialogs is what can be put a ContentView defined by XAML or c# code into each platform native dialog and show it.

The position of a dialog can be specified any position in the screen with VerticalLayoutAlignment, HorizontallayoutAlignment, OffsetX and OffsetY property.

Features

  • Dialog – Showing a general dialog.
  • Toast – Showing what is called a toast.
  • Loading – Showing a full-screen modal dialog for loading.

Usage

var ret = await Dialog.Instance.ShowAsync<MyDialogView>(new{Title="Hello"});
// If canceled, return false. If completed, return true.
// Optionally, you can pass a ViewModel to a DialogView.
// When the dialog is closed, all related resources are automatically disposed of.

Toast.Instance.Show<MyToastView>(new{Title="Hello",Duration=1500});
// Optionally, you can pass a ViewModel to a ToastView.

await Loading.Instance.StartAsync(async progress =>{
    // Heavy process
    for (var i = 0; i < 100; i++)
    {
        await Task.Delay(50);
        // You can send the progress to a dialog with IProgress<double> value.
        progress.Report((i + 1) * 0.01d);
    }
});

For more information about how to use AiForms.Dialogs, see ReadMe.

Concluding

I would be grateful if you could use this library for using an elaborate dialog in a NETStandard project.

If there are some questions, requests, and bug reports, please report it to GitHub issues or twitter.

Top comments (0)