7
7
ReflectiveInjector ,
8
8
Type ,
9
9
ViewContainerRef ,
10
+ ElementRef ,
10
11
} from "@angular/core" ;
11
12
12
13
import { NSLocationStrategy } from "../router/ns-location-strategy" ;
@@ -26,6 +27,8 @@ export interface ModalDialogOptions {
26
27
stretched ?: boolean ;
27
28
viewContainerRef ?: ViewContainerRef ;
28
29
moduleRef ?: NgModuleRef < any > ;
30
+ sourceView ?: ElementRef ;
31
+ ios ?: any ;
29
32
}
30
33
31
34
export class ModalDialogParams {
@@ -46,15 +49,17 @@ interface ShowDialogOptions {
46
49
parentView : ViewBase ;
47
50
resolver : ComponentFactoryResolver ;
48
51
type : Type < any > ;
52
+ ios ?: any ;
49
53
}
50
54
51
55
@Injectable ( )
52
56
export class ModalDialogService {
57
+ private componentView : View ;
53
58
constructor ( private location : NSLocationStrategy ) {
54
59
}
55
60
56
61
public showModal ( type : Type < any > ,
57
- { viewContainerRef, moduleRef, context, fullscreen, animated, stretched } : ModalDialogOptions
62
+ { viewContainerRef, moduleRef, context, fullscreen, animated, stretched, sourceView , ios } : ModalDialogOptions
58
63
) : Promise < any > {
59
64
if ( ! viewContainerRef ) {
60
65
throw new Error (
@@ -63,7 +68,11 @@ export class ModalDialogService {
63
68
) ;
64
69
}
65
70
66
- let parentView = viewContainerRef . element . nativeElement ;
71
+ if ( sourceView ) {
72
+ this . closeModal ( ) ;
73
+ }
74
+
75
+ let parentView = sourceView ? sourceView . nativeElement : viewContainerRef . element . nativeElement ;
67
76
if ( parentView instanceof AppHostView && parentView . ngAppRoot ) {
68
77
parentView = parentView . ngAppRoot ;
69
78
}
@@ -105,6 +114,7 @@ export class ModalDialogService {
105
114
parentView,
106
115
resolver,
107
116
type,
117
+ ios
108
118
} ) ;
109
119
} catch ( err ) {
110
120
reject ( err ) ;
@@ -113,6 +123,13 @@ export class ModalDialogService {
113
123
} ) ;
114
124
}
115
125
126
+ public closeModal ( ) {
127
+ if ( this . componentView ) {
128
+ this . componentView . closeModal ( ) ;
129
+ this . location . _closeModalNavigation ( ) ;
130
+ }
131
+ }
132
+
116
133
private _showDialog ( {
117
134
containerRef,
118
135
context,
@@ -124,6 +141,7 @@ export class ModalDialogService {
124
141
parentView,
125
142
resolver,
126
143
type,
144
+ ios
127
145
} : ShowDialogOptions ) : void {
128
146
let componentView : View ;
129
147
let detachedLoaderRef : ComponentRef < DetachedLoader > ;
@@ -161,7 +179,12 @@ export class ModalDialogService {
161
179
162
180
// TODO: remove <any> cast after https://github.com/NativeScript/NativeScript/pull/5734
163
181
// is in a published version of tns-core-modules.
164
- ( < any > parentView ) . showModal ( componentView , context , closeCallback , fullscreen , animated , stretched ) ;
182
+ if ( ios ) {
183
+ ( < any > parentView ) . showModal ( componentView , { context, closeCallback, fullscreen, animated, stretched, ios } ) ;
184
+ } else {
185
+ ( < any > parentView ) . showModal ( componentView , context , closeCallback , fullscreen , animated , stretched ) ;
186
+ }
187
+ this . componentView = componentView ;
165
188
} ) ;
166
189
}
167
190
}
0 commit comments