dialog close callback implement for Dialog class

This commit is contained in:
Vladimir Enchev
2014-06-12 10:35:51 +03:00
parent aeadff59e5
commit 4028cf4881
3 changed files with 18 additions and 4 deletions

View File

@ -161,10 +161,12 @@ export class Dialog {
private _android: android.app.AlertDialog.Builder; private _android: android.app.AlertDialog.Builder;
//private _view: view.View; //private _view: view.View;
constructor(message: string, options?: dialogs.DialogButtonsOptions) { constructor(message: string, callback?: (result: boolean) => {}, options?: dialogs.DialogButtonsOptions) {
this._android = createAlertDialog(message, options); this._android = createAlertDialog(message, options);
addButtonsToAlertDialog(this.android, options, function (r) { addButtonsToAlertDialog(this.android, options, function (r) {
if (callback) {
callback(r);
}
}); });
} }

View File

@ -117,7 +117,7 @@
} }
export class Dialog { export class Dialog {
constructor(message: string, options?: DialogButtonsOptions); constructor(message: string, callback?: (result: boolean) => {}, options?: DialogButtonsOptions);
/** /**
* Shows the dialog. * Shows the dialog.
*/ */

View File

@ -172,9 +172,21 @@ export class Dialog {
//private _view: view.View; //private _view: view.View;
//private _nativeView: UIKit.UIView; //private _nativeView: UIKit.UIView;
constructor(message: string, options?: dialogs.DialogButtonsOptions) { constructor(message: string, callback?: (result: boolean) => {}, options?: dialogs.DialogButtonsOptions) {
this._ios = createUIAlertView(message, options); this._ios = createUIAlertView(message, options);
addButtonsToAlertDialog(this._ios, options); addButtonsToAlertDialog(this._ios, options);
// Assign first to local variable, otherwise it will be garbage collected since delegate is weak reference.
var delegate = createDelegate(function (view, index) {
if (callback) {
callback(index === 2 ? undefined : index === 0);
}
// Remove the local variable for the delegate.
delegate = undefined;
});
this._ios.delegate = delegate;
} }
get ios(): UIKit.UIAlertView { get ios(): UIKit.UIAlertView {