Code Monkey home page Code Monkey logo

toasts.forms.plugin's Introduction

Toasts Plugin for Xamarin.Forms

A simple way of showing some notifications inside your Xamarin.Forms application. In windows phone world we call them "Toasts".

Android

Android implementation is based on https://github.com/keyboardsurfer/Crouton with several changes and ported to C# without bindings.

Alt text

iOS

iOS implementation is based on https://github.com/terryworona/TWMessageBarManager with several changes (thanks to prashantvc with his https://github.com/prashantvc/Xamarin.iOS-MessageBar)

Alt text

WP8

Unlike others WP8's version supports multiply toasts (can be limited to 1).

Alt text

Setup and usage

Setup

In your iOS, Android, and Windows Phone projects please call:

Xamarin.Forms.Init();//platform specific init
ToastNotificatorImplementation.Init(); //you can pass additional parameters here

You must do this AFTER you call Xamarin.Forms.Init(); By the way, toasts on each platform support customization - you can pass your own style (custom renderer) as an argument in Init() method.

Usage

Use dependency service in order to resolve IToastNotificator

var notificator = DependencyService.Get<IToastNotificator>();
bool tapped = await notificator.Notify(ToastNotificationType.Error, 
	"Error", "Something went wrong", TimeSpan.FromSeconds(2));

Customization

On all three platforms you can completely override toast UI. However, there is also an easy way to add a new status with custom icon and background, let's take a look on a Windows Phone example. In this example we want to add a few more types of messages with custom icons. Our code in PCL will look like this:

var notificator = DependencyService.Get<IToastNotificator>();
bool tapped = await notificator.Notify(
	type: ToastNotificationType.Custom, 
	title: "Level up!", 
	description: "Congratulations!", 
	duration: TimeSpan.FromSeconds(2), 
	context: MyCustomTypes.LevelUp);

So we have just set the type to Custom and passed an additional argument to Object context (last argument) - our custom enum MyCustomTypes.LevelUp. Now we have to configure default renderer (or replace it by your own if you want to add more changes to the layout):

Xamarin.Forms.Forms.Init();
ToastNotificatorImplementation.Init(stackSize: 2, 
	customRenderer: new DefaultToastLayoutRenderer(
		context =>
		{
			switch ((MyCustomTypes)context)
			{
				case MyCustomTypes.LevelUp:
					return new BitmapImage(new Uri("level_up.png", UriKind.Relative));
				...
			}
		}, 
		context => new SolidColorBrush(Colors.Magenta)));

iOS and Android api also have similar extensibility

Contributors

Thanks!

License

Licensed under MIT

toasts.forms.plugin's People

Contributors

egorbo avatar kmormysh avatar canab avatar

Stargazers

Media Explorer avatar

Watchers

James Cloos avatar Matthew Leibowitz 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.