GithubHelp home page GithubHelp logo

caffeinalab / ti.notifications Goto Github PK

View Code? Open in Web Editor NEW
82.0 36.0 22.0 76 KB

Useful Titanium+Alloy widget to handle notifications messages when app is in foreground.

License: MIT License

JavaScript 100.00%

ti.notifications's Introduction

Ti.Notifications

Gitter

com.caffeinalab.titanium.notifications

Alloy Titanium widget to display an in-app notification.

The widget is a tiny view that comes from the top with a simple animation.

image

Cross Platform?

On iOS7+, the animation is managed by Ti.UI.iOS.Animator physics engine (Tweetbot style).

Installation

Via Gittio

gittio install com.caffeinalab.titanium.notifications

Via Github

Download the latest release and add in your config.json, under dependencies:

"dependencies": {
    "com.caffeinalab.titanium.notifications": "*"
}

Require

var Notifier = Alloy.createWidget('com.caffeinalab.titanium.notifications', /* options */);

The Options

{

	message: 'Notification Test', // the message to display.

	duration: 2000, // time after go away. Valid for iOS7+ and Android
	icon: '/appicon.png', // icon to display on the left

	style: 'info', // 'info', 'success', 'error', 'warn',  notification background blue, green, red or amber.

	elasticity: 0.5, // iOS7+ only
	pushForce: 30, // iOS7+ only
	usePhysicsEngine: true, // disable if you don't want on iOS7+

	animationDuration: 200, // animation sliding duration

}

Usage

// Show the widget setting the title
Notifier.show('Hello, world!');

// Show the widget, and override defaults
Notifier.show({
	message: 'Notification Test',
	icon: '/appicon.png',
	pushForce: 10,
	style: 'info', // sets the message background to blue (50% opacity)
	duration: 2500,
	onClick: function(){ alert("OH, you clicked me!\nDo you think I'm weird?"); }
});

// Update the notification text. Useful for loading %
Notifier.setMessage('I updated the notifcation message!');

// Update the notification style. Useful for error and success messages
Notifier.setStyle('error');

// Update the icon to a new one
Notifier.setIcon('/newicon.png');

// Hide
Notifier.hide();

Loading Notification Example (With styling)

var Notifier = Alloy.createWidget('com.caffeinalab.titanium.notifications', { duration: null });
Notifier.show('Loading');

// 50MB test file from thinkbroadband to simulate a slow load.
var url = "http://ipv4.download.thinkbroadband.com:8080/50MB.zip";
var client = Ti.Network.createHTTPClient({
	// function called when the response data is available
	onload : function(e) {
		Notifier.setStyle('success');
		Notifier.setMessage('Successful Download!');
      	setTimeout(Notifier.hide, 3000);
		},
     	// function called at regular intervals as the request data is being received.
     	ondatastream : function(e) {
        	Notifier.setMessage('Loading ' + Math.round(e.progress.toFixed(2)*100) + '%');
     	},
     	// function called when an error occurs, including a timeout
     	onerror : function(e) {
        	Ti.API.debug(e.error);
        	Notifier.setStyle('error');
        	Notifier.setMessage('Error, Please try again.');
        	setTimeout(Notifier.hide, 3000);
     	},
     	timeout: 5000
});
client.open("GET", url);
client.send();

Fully stylable via TSS

Override this options in your app.tss.

".caffeinaToastView":{
	"top": 0,
	"backgroundColor": "#A000",
	"height": 65,
	"touchEnabled": false
},
".caffeinaToastIcon":{
	"left": 8,
	"height": 42
},
".caffeinaToastLabel":{
	"touchEnabled": false,
	"left": 60,
	"right": 10,
	"height": 60,
	"color": "#fff",
	"textAlign": "left",
	"font": {
		"fontSize": 14
	}
}

Work with Android or iOS modal Windows

On Android is not possible to make it work with Windows.

On iOS, with modal Windows, in not possible to open a non-modal window in front of another modal window.

So, to make it work with theese two cases, use the view property on open:

Notifier.show({
	view: /* Your Window/View */
});

Contributing

How to get involved:

  1. Star the project!
  2. Answer questions that come through GitHub issues
  3. Report a bug that you find

Pull requests are highly appreciated.

Solve a problem. Features are great, but even better is cleaning-up and fixing issues in the code that you discover.

Copyright and license

Copyright 2015 Caffeina srl under the MIT license.

ti.notifications's People

Contributors

kopiro avatar adamkearsley avatar jeliasson avatar hazemkhaled avatar jei avatar apzentral avatar shodanuk avatar gitter-badger avatar

Stargazers

Brenton House avatar Waqas Mahmood Khan avatar  avatar sachincredible avatar Shady Shalaby Aly avatar Redouane M. BOUDELLA avatar Manjunath (MJ) avatar Jose Vega avatar PaRnanZio Gun avatar App Inlet avatar Douglas Alves avatar Reilly avatar Darius G avatar Thomas Lemaitre avatar Nando Cammarota avatar Neto Ramalho avatar Andrew McElroy avatar Antonio Duran avatar Eni Sinanaj avatar Adam T Armstrong avatar Umi Uyura avatar  avatar  avatar Hy Dang avatar Ivan Carlos avatar Raef Akehurst avatar Angus H. avatar Haroon Abbasi avatar Conny Brunnkvist avatar Usame Cavga avatar Sebastian Klaus avatar Jumper avatar Francis Reyes avatar Douglas Hennrich avatar Gianfranco Frau avatar Rene Pot avatar  avatar Ianko Leite avatar Vincent Desdoigts avatar Thibault Lenclos avatar Manojkumar Murugesan avatar  avatar Marcelo Cecin avatar Jonathan Wheat avatar Tiziano Tassi avatar Emil Öberg avatar Remigio Morales avatar  avatar Vitor Emanuel Batista avatar Roy Sinclair avatar Santiago Becerra avatar Ivan Morgado avatar Konstantin Büschel avatar Yuriy Nevmerzhitskiy avatar lmy avatar Manuel Conde Vendrell avatar  avatar Miro avatar  avatar Jason David Miller avatar Mahmoud Kamal avatar Marcel Pociot avatar BeauR avatar David Sullivan avatar Adam Pash avatar Iñaki Abete avatar  avatar Abdulatif Henno avatar  avatar Michael Pauley avatar Steven avatar Projets DIY avatar  avatar Achraf Bouyakhsass avatar Joseph avatar samuele coppede avatar Alper Dincer avatar Miguel avatar Manuel Lehner avatar Boydlee Pollentine avatar Gergely Cziva avatar Stefano Azzolini avatar

Watchers

zbage avatar Gabriele Mearelli avatar Stefano Azzolini avatar Carlo Frinolli avatar Thomas Lemaitre avatar  avatar James Cloos avatar Ani Sinanaj avatar Nicholas avatar Tiziano Tassi avatar Adam T Armstrong avatar  avatar  avatar Vitor Emanuel Batista avatar Jonathan Wheat avatar Graziano Vincini avatar Simone Montali avatar  avatar Riccardo Canella avatar Jose Vega avatar Vincent De Feo avatar Fiad avatar Giulio Montagner avatar Vito Famiglietti avatar Gabriele Marconetta avatar Andrea Longo avatar  avatar Mario avatar Stefano Andriolo avatar  avatar Lorenzo Girardi avatar App Inlet avatar Abanoub Zaky avatar Elisa Losito avatar  avatar  avatar

ti.notifications's Issues

Adding Close Event.

What do you think about adding the close callback to be called when notification is completely closed?
Thank you.

On Android Working as a toast only !

HI,

Hope you are doing great!!

I have tried this widget and found on android its not working as expected. Its working as a toast only.

Please provide me the steps to make it work for android. Any help will be appreciated.

Regards,

Click events on modal windows don't work?

Hi.
Firstly... great widget!

Having an issue with the click events on modal windows.

alloy.js

Alloy.Globals.notify = Alloy.createWidget('com.caffeinalab.titanium.notifications');

payment.js

Alloy.Globals.notify.show({
     message: 'Sending Payment',
     pushForce: 20,
     duration: 60000,
     click: function(){ alert("OH, you clicked me!\nDo you think I'm weird?"); },
     view: $.payment
});
setTimeout(function(){
     Alloy.Globals.notify.hide();
}, 5000);

When i click on the notification it just closes.
I don't get the alert as expected.

Hide

I'm missing an Notifier.hide function :)

Style rules not being overwritten

I can't seem to overwrite the styles on a modal window.

app.tss

".caffeinaToastView":{
    top: 0,
    backgroundColor: '#50e97c00',
    height: 75,
    touchEnabled: false,
    layout: 'composite'
},
".caffeinaToastIcon":{
    left: 8,
    height: 42,
    borderRadius: 10
},
".caffeinaToastLabel":{
    touchEnabled: false,
    height: 60,
    color: '#fff',
    textAlign: 'center',
    font: {
        fontSize: 22
    }
}

mywin.js

var notify = Alloy.createWidget('com.caffeinalab.titanium.notifications');
setTimeout(function(){
    notify.show({
        icon: '',
        message: 'Sending Payment',
        pushForce: 20,
        duration: 60000,
        click: function(){ alert("OH, you clicked me!\nDo you think I'm weird?"); },
        view: $.payment
    });
    setTimeout(function(){
        notify.hide();
    }, 5000);
}, 1000);

Notification is still the default color and my color changes in app.tss haven't taken effect.

Show over modal window?

Theres probably a good explanation - but is it not possible to use this when calling it from a modal window?

Doing this: Alloy.createController('myController').getView().open({modal: true});

The notification is shown behind the modal window.

Notifier.show looses focus on Textfield in window

I wonder if that has been experienced by other developers, but imagine a window with text fields.
When a user has focus on a textfield, on return, a Notifier is shown, after the animation finishes, the keyboard looses focus on the textfield.

Multiple push notifications

I want to use this as part of push notifications, if the push notifications are stacked, the banner only shows the last push notification one. How can I use the module to handle this better?

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.