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.
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.
- Install the Toasts Plugin for Xamarin and Windows in your native project and PCL if applicable.
- 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.
In the MainActivity.cs
In the MainPage.xaml.cs
In the AppDelegate.cs
To show a toast anywhere in your application, takes just one easy line of code. (after you get the reference to the Toast Notifier)
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.
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