mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 13:51:27 +08:00
first custom dialogs implementation
This commit is contained in:
@ -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);
|
||||
```
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
22
ui/dialogs/dialogs.d.ts
vendored
22
ui/dialogs/dialogs.d.ts
vendored
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user