diff --git a/ui/dialogs/Readme.md b/ui/dialogs/Readme.md index 19766516d..bb51cdd7e 100644 --- a/ui/dialogs/Readme.md +++ b/ui/dialogs/Readme.md @@ -12,4 +12,16 @@ dialogs.prompt({message:"Enter something?", title: "MyPrompt", okButtonName: "Do it!", cancelButtonName: "Ignore it!", defaultText : "Enter your password here!" }) .then(function(r){ dialogs.alert("Result:" + r); }); +``` +Custom dialogs: +```js + require("globals"); + var dialogs = require("ui/dialogs"); + + /// Splash + var d = new dialogs.Dialog(); + d.title = "Loading..." + d.show(); + + setTimeout(function(){ d.hide(); }, 2000); ``` \ No newline at end of file diff --git a/ui/dialogs/dialogs.android.ts b/ui/dialogs/dialogs.android.ts index 6ac646d1a..bb265c51b 100644 --- a/ui/dialogs/dialogs.android.ts +++ b/ui/dialogs/dialogs.android.ts @@ -98,4 +98,36 @@ export function prompt(arg: any): promises.Promise { } return d.promise(); +} + +export class Dialog { + private _dialog: android.app.AlertDialog; + private _android: android.app.AlertDialog.Builder; + private _title: string; + + constructor() { + this._android = new android.app.AlertDialog.Builder(appmodule.android.foregroundActivity); + } + + get android(): android.app.AlertDialog.Builder { + return this._android; + } + + get title(): string { + return this._title; + } + set title(value: string) { + this._title = value; + this.android.setTitle(this._title); + } + + public show() { + this._dialog = this.android.show(); + } + + public hide() { + if (this._dialog) { + this._dialog.hide(); + } + } } \ No newline at end of file diff --git a/ui/dialogs/dialogs.d.ts b/ui/dialogs/dialogs.d.ts index f65fc56cc..1920efbb6 100644 --- a/ui/dialogs/dialogs.d.ts +++ b/ui/dialogs/dialogs.d.ts @@ -85,4 +85,26 @@ */ defaultText?: string; } + + export class Dialog { + /** + * Shows the dialog. + */ + show: () => void; + + /** + * Hides the dialog. + */ + hide: () => void; + + /** + * Gets or sets dialog title. + */ + title: string; + + /** + * Gets or sets dialog view. + */ + view: any; + } } \ No newline at end of file diff --git a/ui/dialogs/dialogs.ios.ts b/ui/dialogs/dialogs.ios.ts index cd68a3240..1a7bfdb61 100644 --- a/ui/dialogs/dialogs.ios.ts +++ b/ui/dialogs/dialogs.ios.ts @@ -114,4 +114,31 @@ export function prompt(arg: any): promises.Promise { } return d.promise(); +} + +export class Dialog { + private _ios: UIKit.UIAlertView; + + constructor() { + this._ios = new UIKit.UIAlertView(); + } + + get ios(): UIKit.UIAlertView { + return this._ios; + } + + get title(): string { + return this.ios.title; + } + set title(value: string) { + this.ios.title = value; + } + + public show() { + this.ios.show(); + } + + public hide() { + this.ios.dismissWithClickedButtonIndexAnimated(0, true); + } } \ No newline at end of file