Git Product home page Git Product logo

toasts.forms.plugin's Introduction

Toasts Plugin for Xamarin and Windows

A simple way of showing some notifications inside your Xamarin or Windows 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

Platform Support

Platform Supported Version
Xamarin.iOS Yes iOS 7+
Xamarin.iOS Unified Yes iOS 7+
Xamarin.Android Yes API 16+
Windows Phone Silverlight Yes 8.0+
Windows Phone RT Yes 8.1+
Windows Store RT Yes 8.1+
Windows 10 UWP Yes 10+
Xamarin.Mac No

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

DependencyService.Register<ToastNotificatorImplementation>(); // Register your dependency
ToastNotificatorImplementation.Init(); //you can pass additional parameters here
// ToastNotificatorImplementation.Init(this); // In Android ([this] is the current Android Activity)

If you are using Xamarin Forms, you must do this AFTER your call to 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 a 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 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 adamped avatar haroldma-zz avatar kmormysh avatar canab avatar dcasbonne avatar

Watchers

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