first custom dialogs implementation

This commit is contained in:
Vladimir Enchev
2014-06-06 10:01:33 +03:00
parent 459e03d8ed
commit df1d0923d1
4 changed files with 93 additions and 0 deletions

View File

@ -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);
```

View File

@ -98,4 +98,36 @@ export function prompt(arg: any): promises.Promise<string> {
}
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();
}
}
}

View File

@ -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;
}
}

View File

@ -114,4 +114,31 @@ export function prompt(arg: any): promises.Promise<string> {
}
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);
}
}