@@ -163,7 +163,7 @@ function prepareAndCreateAlertDialog(
163
163
) {
164
164
// onDismiss will always be called. Prevent calling callback multiple times
165
165
let onDoneCalled = false ;
166
- const onDone = function ( result : boolean , dialog ?: android . content . DialogInterface ) {
166
+ const onDone = function ( result : boolean , dialog ?: android . content . DialogInterface , toBeCalledBeforeCallback ? ) {
167
167
if ( options && options . shouldResolveOnAction && ! options . shouldResolveOnAction ( validationArgs ? validationArgs ( result ) : result ) ) {
168
168
return ;
169
169
}
@@ -186,6 +186,9 @@ function prepareAndCreateAlertDialog(
186
186
if ( dialog ) {
187
187
dialog . cancel ( ) ;
188
188
}
189
+ if ( toBeCalledBeforeCallback ) {
190
+ toBeCalledBeforeCallback ( ) ;
191
+ }
189
192
callback && callback ( result ) ;
190
193
} ;
191
194
if ( ! DialogInterface ) {
@@ -194,14 +197,16 @@ function prepareAndCreateAlertDialog(
194
197
builder . setOnDismissListener (
195
198
new DialogInterface . OnDismissListener ( {
196
199
onDismiss ( ) {
197
- onDone ( false ) ;
198
- if ( ( builder as any ) . _currentModalCustomView ) {
199
- const view = ( builder as any ) . _currentModalCustomView ;
200
- view . callUnloaded ( ) ;
201
- view . _tearDownUI ( true ) ;
202
- view . _isAddedToNativeVisualTree = false ;
203
- ( builder as any ) . _currentModalCustomView = null ;
204
- }
200
+ // ensure callback is called after destroying the custom view
201
+ onDone ( false , undefined , ( ) => {
202
+ if ( ( builder as any ) . _currentModalCustomView ) {
203
+ const view = ( builder as any ) . _currentModalCustomView ;
204
+ view . callUnloaded ( ) ;
205
+ view . _tearDownUI ( true ) ;
206
+ view . _isAddedToNativeVisualTree = false ;
207
+ ( builder as any ) . _currentModalCustomView = null ;
208
+ }
209
+ } ) ;
205
210
}
206
211
} )
207
212
) ;
@@ -335,12 +340,13 @@ export class AlertDialog {
335
340
}
336
341
async hide ( ) {
337
342
if ( this . dialog ) {
338
- return new Promise ( ( resolve ) => {
343
+ return new Promise < void > ( ( resolve ) => {
339
344
this . onCloseListeners . push ( resolve ) ;
340
345
this . dialog . cancel ( ) ;
341
346
this . dialog = null ;
342
347
} ) ;
343
348
}
349
+ return null ;
344
350
}
345
351
}
346
352
0 commit comments