@@ -11,6 +11,7 @@ import {
11
11
12
12
import { Page } from "tns-core-modules/ui/page" ;
13
13
import { View , ViewBase } from "tns-core-modules/ui/core/view" ;
14
+ import { ProxyViewContainer } from "tns-core-modules/ui/proxy-view-container/proxy-view-container" ;
14
15
15
16
import { AppHostView } from "../app-host-view" ;
16
17
import { DetachedLoader } from "../common/detached-loader" ;
@@ -89,41 +90,43 @@ export class ModalDialogService {
89
90
resolver,
90
91
type,
91
92
} : ShowDialogOptions ) : void {
92
- const page = pageFactory ( { isModal : true , componentType : type } ) ;
93
-
93
+ let componentView : View ;
94
94
let detachedLoaderRef : ComponentRef < DetachedLoader > ;
95
+
95
96
const closeCallback = ( ...args ) => {
96
97
doneCallback . apply ( undefined , args ) ;
97
- page . closeModal ( ) ;
98
+ if ( componentView ) {
99
+ componentView . closeModal ( ) ;
100
+ }
98
101
detachedLoaderRef . instance . detectChanges ( ) ;
99
102
detachedLoaderRef . destroy ( ) ;
100
103
} ;
101
104
102
105
const modalParams = new ModalDialogParams ( context , closeCallback ) ;
103
-
104
106
const providers = ReflectiveInjector . resolve ( [
105
- { provide : Page , useValue : page } ,
106
107
{ provide : ModalDialogParams , useValue : modalParams } ,
107
108
] ) ;
108
109
109
- const childInjector = ReflectiveInjector . fromResolvedProviders (
110
- providers , containerRef . parentInjector ) ;
110
+ const childInjector = ReflectiveInjector . fromResolvedProviders ( providers , containerRef . parentInjector ) ;
111
111
const detachedFactory = resolver . resolveComponentFactory ( DetachedLoader ) ;
112
112
detachedLoaderRef = containerRef . createComponent ( detachedFactory , - 1 , childInjector , null ) ;
113
113
detachedLoaderRef . instance . loadComponent ( type ) . then ( ( compRef ) => {
114
- const componentView = < View > compRef . location . nativeElement ;
114
+ const detachedProxy = < ProxyViewContainer > compRef . location . nativeElement ;
115
+
116
+ if ( detachedProxy . getChildrenCount ( ) > 1 ) {
117
+ throw new Error ( "Modal contet has more than one root view." ) ;
118
+ }
119
+ componentView = detachedProxy . getChildAt ( 0 ) ;
115
120
116
121
if ( componentView . parent ) {
117
122
( < any > componentView . parent ) . removeChild ( componentView ) ;
118
123
}
119
124
120
- page . content = componentView ;
121
- parentView . showModal ( page , context , closeCallback , fullscreen ) ;
125
+ parentView . showModal ( componentView , context , closeCallback , fullscreen ) ;
122
126
} ) ;
123
127
}
124
128
}
125
129
126
-
127
130
@Directive ( {
128
131
selector : "[modal-dialog-host]" // tslint:disable-line:directive-selector
129
132
} )
0 commit comments