mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
confirm implemented for ios
This commit is contained in:
41
ui/dialogs/dialogs.d.ts
vendored
41
ui/dialogs/dialogs.d.ts
vendored
@@ -13,10 +13,16 @@
|
|||||||
function alert(options: AlertOptions): promises.Promise<any>;
|
function alert(options: AlertOptions): promises.Promise<any>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.
|
* The confirm() method displays a dialog box with a specified message.
|
||||||
* @param message Specifies the text to display in the confirm box.
|
* @param message Specifies the text to display in the confirm box.
|
||||||
*/
|
*/
|
||||||
function confirm(message: string): void;
|
function confirm(message: string): promises.Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The confirm() method displays a dialog box with a specified message.
|
||||||
|
* @param options Specifies the options for the confirm box.
|
||||||
|
*/
|
||||||
|
function confirm(options: ConfirmOptions): promises.Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The prompt() method displays a dialog box that prompts the visitor for input.
|
* The prompt() method displays a dialog box that prompts the visitor for input.
|
||||||
@@ -35,13 +41,38 @@
|
|||||||
message: string;
|
message: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or sets the alert message.
|
* Gets or sets the alert title.
|
||||||
*/
|
*/
|
||||||
title?: string;
|
title?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or sets the request headers in JSON format.
|
* Gets or sets the button name.
|
||||||
*/
|
*/
|
||||||
buttonName?: any;
|
buttonName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides options for the alert.
|
||||||
|
*/
|
||||||
|
interface ConfirmOptions {
|
||||||
|
/**
|
||||||
|
* Gets or sets the alert message.
|
||||||
|
*/
|
||||||
|
message: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the alert title.
|
||||||
|
*/
|
||||||
|
title?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the OK button name.
|
||||||
|
*/
|
||||||
|
okButtonName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the Cancel button name.
|
||||||
|
*/
|
||||||
|
cancelButtonName?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,27 +3,41 @@
|
|||||||
*/
|
*/
|
||||||
import promises = require("promises");
|
import promises = require("promises");
|
||||||
|
|
||||||
|
function createUIAlertView(options) {
|
||||||
|
var alert = new UIKit.UIAlertView();
|
||||||
|
alert.title = options.title;
|
||||||
|
alert.message = options.message;
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDelegate(callback) {
|
||||||
|
var delegateType = Foundation.NSObject.extends({}, {}).implements({
|
||||||
|
protocol: "UIAlertViewDelegate",
|
||||||
|
implementation: {
|
||||||
|
alertViewClickedButtonAtIndex: function (view, index) {
|
||||||
|
callback(view, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return new delegateType;
|
||||||
|
}
|
||||||
|
|
||||||
export function alert(arg: any): promises.Promise<any> {
|
export function alert(arg: any): promises.Promise<any> {
|
||||||
var d = promises.defer<any>();
|
var d = promises.defer<any>();
|
||||||
try {
|
try {
|
||||||
var options = typeof arg === "string" ? { message: arg, title: "Alert", buttonName: "OK" } : arg
|
var options = typeof arg === "string" ? { message: arg, title: "Alert", buttonName: "OK" } : arg
|
||||||
var alert = new UIKit.UIAlertView();
|
|
||||||
alert.title = options.title;
|
var alert = createUIAlertView(options);
|
||||||
alert.message = options.message;
|
|
||||||
alert.addButtonWithTitle(options.buttonName);
|
alert.addButtonWithTitle(options.buttonName);
|
||||||
|
|
||||||
var delegateType = Foundation.NSObject.extends({}, {}).implements({
|
|
||||||
protocol: "UIAlertViewDelegate",
|
|
||||||
implementation: {
|
|
||||||
alertViewClickedButtonAtIndex: function (view, index) {
|
|
||||||
d.resolve();
|
|
||||||
// Remove the local variable for the delegate.
|
|
||||||
delegate = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
|
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
|
||||||
var delegate = new delegateType();
|
var delegate = createDelegate(function (view, index) {
|
||||||
|
d.resolve();
|
||||||
|
// Remove the local variable for the delegate.
|
||||||
|
delegate = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
alert.delegate = delegate;
|
alert.delegate = delegate;
|
||||||
|
|
||||||
alert.show();
|
alert.show();
|
||||||
@@ -34,8 +48,32 @@ export function alert(arg: any): promises.Promise<any> {
|
|||||||
return d.promise();
|
return d.promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function confirm(message: string): void {
|
export function confirm(arg: any): promises.Promise<boolean> {
|
||||||
|
var d = promises.defer<boolean>();
|
||||||
|
try {
|
||||||
|
var options = typeof arg === "string" ? { message: arg, title: "Alert", okButtonName: "OK", cancelButtonName: "Cancel" } : arg
|
||||||
|
|
||||||
|
var alert = createUIAlertView(options);
|
||||||
|
|
||||||
|
alert.addButtonWithTitle(options.okButtonName);
|
||||||
|
alert.addButtonWithTitle(options.cancelButtonName);
|
||||||
|
|
||||||
|
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
|
||||||
|
var delegate = createDelegate(function (view, index) {
|
||||||
|
d.resolve(index === 0);
|
||||||
|
// Remove the local variable for the delegate.
|
||||||
|
delegate = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.delegate = delegate;
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
d.reject(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function prompt(text: string, defaultText?: string): void {
|
export function prompt(text: string, defaultText?: string): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user