@@ -163,7 +163,7 @@ function prepareAndCreateAlertDialog(
163163) {
164164 // onDismiss will always be called. Prevent calling callback multiple times
165165 let onDoneCalled = false ;
166- const onDone = function ( result : boolean , dialog ?: android . content . DialogInterface ) {
166+ const onDone = function ( result : boolean , dialog ?: android . content . DialogInterface , toBeCalledBeforeCallback ? ) {
167167 if ( options && options . shouldResolveOnAction && ! options . shouldResolveOnAction ( validationArgs ? validationArgs ( result ) : result ) ) {
168168 return ;
169169 }
@@ -186,6 +186,9 @@ function prepareAndCreateAlertDialog(
186186 if ( dialog ) {
187187 dialog . cancel ( ) ;
188188 }
189+ if ( toBeCalledBeforeCallback ) {
190+ toBeCalledBeforeCallback ( ) ;
191+ }
189192 callback && callback ( result ) ;
190193 } ;
191194 if ( ! DialogInterface ) {
@@ -194,14 +197,16 @@ function prepareAndCreateAlertDialog(
194197 builder . setOnDismissListener (
195198 new DialogInterface . OnDismissListener ( {
196199 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+ } ) ;
205210 }
206211 } )
207212 ) ;
@@ -335,12 +340,13 @@ export class AlertDialog {
335340 }
336341 async hide ( ) {
337342 if ( this . dialog ) {
338- return new Promise ( ( resolve ) => {
343+ return new Promise < void > ( ( resolve ) => {
339344 this . onCloseListeners . push ( resolve ) ;
340345 this . dialog . cancel ( ) ;
341346 this . dialog = null ;
342347 } ) ;
343348 }
349+ return null ;
344350 }
345351}
346352
0 commit comments