Toasts Plugin For Xamarin And Windows

Update: This article is for version 2.0.4 and below of the Toasts plugin. If you wish to use 3.0.0+, please look at Toast Notifications for Xamarin Forms.

As a recent contributor to the Toasts Plugin For Xamarin and Windows I thought it would be good to write about what it does and how you can use it in your project now that there we have finally released version 2.0.0. The major update was support for WinRT and by default UWP along with a few minor bug fixes and a breaking namespace change to align with other Xamarin Plugins.

Toasts

For those that might have come from the iOS side, Toasts are what Windows and Android call Local Notifications. A small message that pops up on the screen to let the user know that some event has occurred. You then have the option to click on the toast to perform an action if it is configured.

android   ios   windows

Setup

  1. Install the Toasts Plugin for Xamarin and Windows in your native project and PCL if applicable.
  2. Add in the appropriate initialization code in each native project.

Note: You don’t have to use Xamarin Forms inbuilt dependency injection, you can use any one that might better suit your project.

Android

In the MainActivity.cs

Android

Windows

In the MainPage.xaml.cs

Windows

iOS

In the AppDelegate.cs

iOS

Usage

To show a toast anywhere in your application, takes just one easy line of code. (after you get the reference to the Toast Notifier)

Customization

One of the great things about the plugin is it lets you override the rendering of the toasts to however you want. You will need to create a new ToastLayoutRenderer for each platform you wish to customize. The easiest way to see how it all works is to look at the default toast layout renderers in the plugin source code

When you create your own, just pass it in the Init() method in each native platform as appropriate.

Roadmap

This is more of a what I intend to do but offer no guarantees when or if it will be completed

  • Use Snackbar for Android instead of Croutons
  • Allow toasts to launch an action upon click
  • Toasts at the bottom of the screen

 

 

 


Posted

in

by

Tags: