@@ -22,6 +22,7 @@ export class NativeModalRef {
2222 modalViewRef : NgViewRef < any > ;
2323
2424 private _closeCallback : ( ) => void ;
25+ private _isDismissed = false ;
2526
2627 constructor ( private _config : NativeDialogConfig , private _injector : Injector , @Optional ( ) private location ?: NSLocationStrategy ) {
2728 let parentView = this . _config . viewContainerRef ?. element . nativeElement || Application . getRootView ( ) ;
@@ -38,10 +39,12 @@ export class NativeModalRef {
3839 }
3940 this . parentView = parentView ;
4041
41- this . _closeCallback = once ( ( ) => {
42+ this . _closeCallback = once ( async ( ) => {
4243 this . stateChanged . next ( { state : 'closing' } ) ;
43- this . modalViewRef . firstNativeLikeView ?. closeModal ( ) ;
44- this . location ?. _closeModalNavigation ( ) ;
44+ if ( ! this . _isDismissed ) {
45+ this . modalViewRef . firstNativeLikeView ?. closeModal ( ) ;
46+ }
47+ await this . location ?. _closeModalNavigation ( ) ;
4548 // this.detachedLoaderRef?.destroy();
4649 if ( this . modalViewRef ?. firstNativeLikeView . isLoaded ) {
4750 fromEvent ( this . modalViewRef . firstNativeLikeView , 'unloaded' )
@@ -81,8 +84,8 @@ export class NativeModalRef {
8184 this . parentView . showModal ( this . modalViewRef . firstNativeLikeView , {
8285 context : null ,
8386 ...userOptions ,
84- closeCallback : ( ) => {
85- this . location ?. _closeModalNavigation ( ) ;
87+ closeCallback : async ( ) => {
88+ await this . location ?. _closeModalNavigation ( ) ;
8689 this . onDismiss . next ( ) ;
8790 this . onDismiss . complete ( ) ;
8891 } ,
@@ -113,8 +116,9 @@ export class NativeModalRef {
113116 this . parentView . showModal ( this . modalViewRef . firstNativeLikeView , {
114117 context : null ,
115118 ...userOptions ,
116- closeCallback : ( ) => {
117- this . location ?. _closeModalNavigation ( ) ;
119+ closeCallback : async ( ) => {
120+ this . _isDismissed = true ;
121+ this . _closeCallback ( ) ; // close callback can only be called once, so we call it here to setup the exit events
118122 this . onDismiss . next ( ) ;
119123 this . onDismiss . complete ( ) ;
120124 } ,
0 commit comments