mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 03:01:51 +08:00
prompt implemented for iOS
This commit is contained in:
36
ui/dialogs/dialogs.d.ts
vendored
36
ui/dialogs/dialogs.d.ts
vendored
@ -27,14 +27,19 @@
|
||||
/**
|
||||
* The prompt() method displays a dialog box that prompts the visitor for input.
|
||||
* @param text The text to display in the dialog box.
|
||||
* @param defaultText The default input value.
|
||||
*/
|
||||
function prompt(text: string, defaultText?: string): void;
|
||||
|
||||
/**
|
||||
* The prompt() method displays a dialog box that prompts the visitor for input.
|
||||
* @param options The options for the dialog box.
|
||||
*/
|
||||
function prompt(options: PromptOptions): void;
|
||||
|
||||
/**
|
||||
* Provides options for the alert.
|
||||
*/
|
||||
interface AlertOptions {
|
||||
interface DialogOptions {
|
||||
/**
|
||||
* Gets or sets the alert message.
|
||||
*/
|
||||
@ -44,7 +49,12 @@
|
||||
* Gets or sets the alert title.
|
||||
*/
|
||||
title?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the alert.
|
||||
*/
|
||||
interface AlertOptions extends DialogOptions {
|
||||
/**
|
||||
* Gets or sets the button name.
|
||||
*/
|
||||
@ -54,17 +64,7 @@
|
||||
/**
|
||||
* Provides options for the alert.
|
||||
*/
|
||||
interface ConfirmOptions {
|
||||
/**
|
||||
* Gets or sets the alert message.
|
||||
*/
|
||||
message: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the alert title.
|
||||
*/
|
||||
title?: string;
|
||||
|
||||
interface ConfirmOptions extends DialogOptions {
|
||||
/**
|
||||
* Gets or sets the OK button name.
|
||||
*/
|
||||
@ -75,4 +75,14 @@
|
||||
*/
|
||||
cancelButtonName?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides options for the alert.
|
||||
*/
|
||||
interface PromptOptions extends ConfirmOptions {
|
||||
/**
|
||||
* Gets or sets the default text.
|
||||
*/
|
||||
defaultText?: string;
|
||||
}
|
||||
}
|
@ -76,6 +76,35 @@ export function confirm(arg: any): promises.Promise<boolean> {
|
||||
return d.promise();
|
||||
}
|
||||
|
||||
export function prompt(text: string, defaultText?: string): void {
|
||||
export function prompt(arg: any): promises.Promise<string> {
|
||||
var d = promises.defer<string>();
|
||||
try {
|
||||
var options = typeof arg === "string" ? { message: arg, title: "Alert", okButtonName: "OK", cancelButtonName: "Cancel" } : arg
|
||||
|
||||
var alert = createUIAlertView(options);
|
||||
alert.alertViewStyle = UIKit.UIAlertViewStyle.UIAlertViewStylePlainTextInput;
|
||||
alert.addButtonWithTitle(options.okButtonName);
|
||||
alert.addButtonWithTitle(options.cancelButtonName);
|
||||
|
||||
var textField = alert.textFieldAtIndex(0);
|
||||
textField.text = options.defaultText ? options.defaultText : "";
|
||||
|
||||
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
|
||||
var delegate = createDelegate(function (view, index) {
|
||||
if (index === 0) {
|
||||
d.resolve(textField.text);
|
||||
}
|
||||
// Remove the local variable for the delegate.
|
||||
delegate = undefined;
|
||||
});
|
||||
|
||||
alert.delegate = delegate;
|
||||
|
||||
alert.show();
|
||||
|
||||
} catch (ex) {
|
||||
d.reject(ex);
|
||||
}
|
||||
|
||||
return d.promise();
|
||||
}
|
Reference in New Issue
Block a user