2015-11-29 08:26:55 +08:00
|
|
|
import {Plugin, Cordova} from './plugin';
|
2016-02-18 03:37:48 +08:00
|
|
|
import {Observable} from 'rxjs/Observable';
|
2015-11-29 06:52:05 +08:00
|
|
|
|
2016-02-18 03:37:48 +08:00
|
|
|
export interface ToastOptions {
|
|
|
|
message?: string;
|
|
|
|
duration?: string;
|
|
|
|
position?: string;
|
|
|
|
addPixelsY?: number;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* This plugin allows you to show a native Toast (a little text popup) on iOS, Android and WP8. It's great for showing a non intrusive native notification which is guaranteed always in the viewport of the browser.
|
|
|
|
*
|
|
|
|
* Requires Cordova plugin: `cordova-plugin-x-toast`. For more info, please see the [Toast plugin docs](https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin).
|
|
|
|
*/
|
2015-11-29 08:26:55 +08:00
|
|
|
@Plugin({
|
2015-11-29 06:52:05 +08:00
|
|
|
plugin: 'cordova-plugin-x-toast',
|
2015-11-30 06:30:15 +08:00
|
|
|
pluginRef: 'plugins.toast',
|
|
|
|
repo: 'https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin'
|
2015-11-29 08:26:55 +08:00
|
|
|
})
|
|
|
|
export class Toast {
|
2015-11-29 06:52:05 +08:00
|
|
|
|
2016-02-18 03:37:48 +08:00
|
|
|
/**
|
|
|
|
* Show a native toast for the given duration at the specified position.
|
|
|
|
*
|
|
|
|
* @param {string} message The message to display.
|
|
|
|
* @param {string} duration Duration to show the toast, either 'short' or 'long'.
|
|
|
|
* @param {string} position Where to position the toast, either 'top', 'center', or 'bottom'.
|
|
|
|
* @return {Observable} Returns an Observable that notifies first on success and then when tapped, rejects on error.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'hide'
|
|
|
|
})
|
|
|
|
static show(message: string, duration: string, position: string){
|
|
|
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Observable, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Observable<any>(observer => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manually hide any currently visible toast.
|
|
|
|
* @return {Promise} Returns a Promise that resolves on success.
|
|
|
|
*/
|
2015-12-01 00:11:48 +08:00
|
|
|
@Cordova()
|
2016-02-18 03:37:48 +08:00
|
|
|
static hide(){
|
|
|
|
// This Promise is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Promise, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Promise<any>((res, rej) => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a native toast with the given options.
|
|
|
|
*
|
|
|
|
* @param {Object} options Options for showing a toast. Available options:
|
|
|
|
* message The message to display.
|
|
|
|
* duration Duration to show the toast, either 'short' or 'long'.
|
|
|
|
* position Where to position the toast, either 'top', 'center', or 'bottom'.
|
|
|
|
* addPixelsY Offset in pixels to move the toast up or down from its specified position.
|
|
|
|
*
|
|
|
|
* @return {Observable} Returns an Observable that notifies first on success and then when tapped, rejects on error.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'hide'
|
|
|
|
})
|
|
|
|
static showWithOptions(options: ToastOptions){
|
|
|
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Observable, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Observable<any>(observer => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand for `show(message, 'short', 'top')`.
|
|
|
|
* @return {Observable} Returns an Observable that notifies first on success and then when tapped, rejects on error.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'hide'
|
|
|
|
})
|
|
|
|
static showShortTop(message: string){
|
|
|
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Observable, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Observable<any>(observer => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand for `show(message, 'short', 'center')`.
|
|
|
|
* @return {Observable} Returns an Observable that notifies first on success and then when tapped, rejects on error.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'hide'
|
|
|
|
})
|
|
|
|
static showShortCenter(message: string){
|
|
|
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Observable, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Observable<any>(observer => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand for `show(message, 'short', 'bottom')`.
|
|
|
|
* @return {Observable} Returns an Observable that notifies first on success and then when tapped, rejects on error.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'hide'
|
|
|
|
})
|
|
|
|
static showShortBottom(message: string){
|
|
|
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Observable, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Observable<any>(observer => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand for `show(message, 'long', 'top')`.
|
|
|
|
* @return {Observable} Returns an Observable that notifies first on success and then when tapped, rejects on error.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'hide'
|
|
|
|
})
|
|
|
|
static showLongTop(message: string){
|
|
|
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Observable, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Observable<any>(observer => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand for `show(message, 'long', 'center')`.
|
|
|
|
* @return {Observable} Returns an Observable that notifies first on success and then when tapped, rejects on error.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'hide'
|
|
|
|
})
|
|
|
|
static showLongCenter(message: string){
|
|
|
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Observable, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Observable<any>(observer => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand for `show(message, 'long', 'bottom')`.
|
|
|
|
* @return {Observable} Returns an Observable that notifies first on success and then when tapped, rejects on error.
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'hide'
|
|
|
|
})
|
|
|
|
static showLongBottom(message: string){
|
|
|
|
// This Observable is replaced by one from the @Cordova decorator that wraps
|
|
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
|
|
// knows that the correct return type is Observable, because there's no way
|
|
|
|
// for it to know the return type from a decorator.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
|
|
return new Observable<any>(observer => {});
|
|
|
|
}
|
2015-11-29 06:52:05 +08:00
|
|
|
}
|