Skip to content

Commit b1383a2

Browse files
committed
fix(dialogs): android fix for AlertDialog onClose event not getting params
1 parent 242df7d commit b1383a2

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/dialogs/dialogs-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface MDCAlertControlerOptions {
1717
customTitleView?: View;
1818
view?: ViewBase | string;
1919
context?: any;
20+
dismissOnBackgroundTap?: boolean;
2021
closeCallback?: Function;
2122
shouldResolveOnAction?: (result) => boolean;
2223
}

src/dialogs/dialogs.android.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ function prepareAndCreateAlertDialog(
221221
view.bindingContext = fromObject(context);
222222
}
223223

224+
if (options.dismissOnBackgroundTap !== undefined) {
225+
dlg.setCanceledOnTouchOutside(options.dismissOnBackgroundTap);
226+
}
227+
224228
if (options.okButtonText) {
225229
if (!DialogInterface) {
226230
DialogInterface = android.content.DialogInterface;
@@ -314,17 +318,17 @@ export class AlertDialog {
314318
dialog: androidx.appcompat.app.AlertDialog;
315319
constructor(private options: any) {}
316320
onCloseListeners: any[] = [];
317-
onClosed() {
318-
this.onCloseListeners.forEach((l) => l());
321+
onClosed(...args) {
322+
this.onCloseListeners.forEach((l) => l(...args));
319323
this.onCloseListeners = [];
320324
}
321325
show(onClosed?) {
322326
if (!this.dialog) {
323327
const alert = createAlertDialogBuilder(this.options);
324328
this.dialog = alert.create();
325-
this.dialog = prepareAndCreateAlertDialog(alert, this.options, () => {
326-
this.onClosed();
327-
onClosed?.();
329+
this.dialog = prepareAndCreateAlertDialog(alert, this.options, (...args) => {
330+
this.onClosed(...args);
331+
onClosed?.(...args);
328332
});
329333
showDialog(this.dialog, this.options);
330334
}

src/dialogs/dialogs.ios.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ function createAlertController(options: DialogOptions & MDCAlertControlerOptions
213213
if (options && options.cancelable === false) {
214214
alertController.mdc_dialogPresentationController.dismissOnBackgroundTap = false;
215215
}
216+
if (options && options.dismissOnBackgroundTap === false) {
217+
alertController.mdc_dialogPresentationController.dismissOnBackgroundTap = false;
218+
}
216219

217220
// const transitionController = MDCDialogTransitionController.alloc().init()
218221
// alertController.modalPresentationStyle = UIModalPresentationStyle.Custom;

0 commit comments

Comments
 (0)