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 {
|
2016-03-26 08:49:42 +08:00
|
|
|
/**
|
|
|
|
* Message to display
|
|
|
|
*/
|
2016-02-18 03:37:48 +08:00
|
|
|
message?: string;
|
2016-03-26 08:49:42 +08:00
|
|
|
/**
|
|
|
|
* Duration in ms to show
|
|
|
|
*/
|
2016-02-18 03:37:48 +08:00
|
|
|
duration?: string;
|
2016-03-26 08:49:42 +08:00
|
|
|
/**
|
|
|
|
* Position
|
|
|
|
*/
|
2016-02-18 03:37:48 +08:00
|
|
|
position?: string;
|
2016-03-26 08:49:42 +08:00
|
|
|
/**
|
|
|
|
* Add negative value to move it up a bit
|
|
|
|
*/
|
2016-02-18 03:37:48 +08:00
|
|
|
addPixelsY?: number;
|
2016-03-26 08:49:42 +08:00
|
|
|
/**
|
|
|
|
* Pass JSON object to be sent back in success callback
|
|
|
|
*/
|
|
|
|
data?: any;
|
|
|
|
/**
|
|
|
|
* Styling
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
styling?: {
|
|
|
|
opacity?: number;
|
|
|
|
backgroundColor?: string;
|
|
|
|
textColor?: string;
|
|
|
|
cornerRadius?: number;
|
|
|
|
horizontalPadding?: number;
|
|
|
|
verticalPadding?: number;
|
2016-03-26 08:49:42 +08:00
|
|
|
};
|
2016-02-18 03:37:48 +08:00
|
|
|
}
|
|
|
|
/**
|
2016-03-13 07:30:16 +08:00
|
|
|
* @name Toast
|
|
|
|
* @description
|
2016-02-18 03:37:48 +08:00
|
|
|
* 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).
|
2016-03-13 07:30:16 +08:00
|
|
|
*
|
|
|
|
* @usage
|
|
|
|
* ```ts
|
2016-03-24 10:48:23 +08:00
|
|
|
* import {Toast} from 'ionic-native';
|
2016-03-25 01:00:18 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
2016-03-13 07:30:16 +08:00
|
|
|
* Toast.show("I'm a toast", 5000, "center").subscribe(
|
|
|
|
* toast => {
|
|
|
|
* console.log(toast);
|
|
|
|
* }
|
|
|
|
* );
|
|
|
|
* ```
|
2016-02-18 03:37:48 +08:00
|
|
|
*/
|
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.
|
2016-03-18 04:36:35 +08:00
|
|
|
* @param {string} duration Duration to show the toast, either 'short', 'long' or any number of milliseconds: '1500'.
|
2016-02-18 03:37:48 +08:00
|
|
|
* @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'
|
|
|
|
})
|
2016-03-11 05:48:20 +08:00
|
|
|
static show(
|
|
|
|
message: string,
|
|
|
|
duration: string,
|
|
|
|
position: string
|
2016-04-30 11:56:49 +08:00
|
|
|
): Observable<any> { return; }
|
2016-02-18 03:37:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04-30 11:56:49 +08:00
|
|
|
static hide(): Promise<any> { return; }
|
2016-02-18 03:37:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a native toast with the given options.
|
|
|
|
*
|
|
|
|
* @param {Object} options Options for showing a toast. Available options:
|
|
|
|
* message The message to display.
|
2016-03-18 04:36:35 +08:00
|
|
|
* duration Duration to show the toast, either 'short', 'long' or any number of milliseconds: '1500'.
|
2016-02-18 03:37:48 +08:00
|
|
|
* 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'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static showWithOptions(options: ToastOptions): Observable<any> { return; }
|
2016-02-18 03:37:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static showShortTop(message: string): Observable<any> { return; }
|
2016-02-18 03:37:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static showShortCenter(message: string): Observable<any> { return; }
|
2016-03-11 05:48:20 +08:00
|
|
|
|
2016-02-18 03:37:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static showShortBottom(message: string): Observable<any> { return; }
|
2016-03-11 05:48:20 +08:00
|
|
|
|
2016-02-18 03:37:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static showLongTop(message: string): Observable<any> { return; }
|
2016-03-11 05:48:20 +08:00
|
|
|
|
2016-02-18 03:37:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static showLongCenter(message: string): Observable<any> { return; }
|
2016-03-11 05:48:20 +08:00
|
|
|
|
2016-02-18 03:37:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static showLongBottom(message: string): Observable<any> { return; }
|
2016-03-11 05:48:20 +08:00
|
|
|
|
2015-11-29 06:52:05 +08:00
|
|
|
}
|