@@ -118,6 +118,7 @@ class IOSApplication implements IOSApplicationDefinition {
118
118
this . _rootView = rootView ;
119
119
const controller = getViewController ( rootView ) ;
120
120
this . _window . rootViewController = controller ;
121
+ rootView . _setupAsRootView ( { } ) ;
121
122
this . _window . makeKeyAndVisible ( ) ;
122
123
}
123
124
@@ -199,8 +200,7 @@ function createRootView(v?: View) {
199
200
// try to navigate to the mainEntry (if specified)
200
201
if ( mainEntry ) {
201
202
if ( createRootFrame ) {
202
- const frame = new Frame ( ) ;
203
- rootView = frame ;
203
+ const frame = rootView = new Frame ( ) ;
204
204
frame . navigate ( mainEntry ) ;
205
205
} else {
206
206
rootView = createViewFromEntry ( mainEntry ) ;
@@ -211,7 +211,6 @@ function createRootView(v?: View) {
211
211
}
212
212
}
213
213
214
- rootView . _setupAsRootView ( { } ) ;
215
214
return rootView ;
216
215
}
217
216
@@ -230,6 +229,7 @@ export function start(entry?: string | NavigationEntry) {
230
229
// Normal NativeScript app will need UIApplicationMain.
231
230
UIApplicationMain ( 0 , null , null , iosApp && iosApp . delegate ? NSStringFromClass ( < any > iosApp . delegate ) : NSStringFromClass ( Responder ) ) ;
232
231
} else {
232
+ // TODO: this rootView should be held alive until rootController dismissViewController is called.
233
233
const rootView = createRootView ( ) ;
234
234
if ( rootView ) {
235
235
// Attach to the existing iOS app
@@ -238,6 +238,7 @@ export function start(entry?: string | NavigationEntry) {
238
238
const rootController = window . rootViewController ;
239
239
if ( rootController ) {
240
240
const controller = getViewController ( rootView ) ;
241
+ rootView . _setupAsRootView ( { } ) ;
241
242
rootController . presentViewControllerAnimatedCompletion ( controller , true , null ) ;
242
243
}
243
244
}
@@ -258,13 +259,17 @@ function getViewController(view: View): UIViewController {
258
259
let viewController : UIViewController = view . viewController || view . ios ;
259
260
if ( viewController instanceof UIViewController ) {
260
261
return viewController ;
261
- } else if ( view . ios instanceof UIView ) {
262
- viewController = iosView . UILayoutViewController . initWithOwner ( new WeakRef ( view ) ) as UIViewController ;
263
- viewController . view . addSubview ( view . ios ) ;
264
- return viewController ;
265
262
} else {
266
- throw new Error ( "Root should be either UIViewController or UIView" ) ;
263
+ const nativeView = view . ios || view . nativeViewProtected ;
264
+ if ( nativeView instanceof UIView ) {
265
+ viewController = iosView . UILayoutViewController . initWithOwner ( new WeakRef ( view ) ) as UIViewController ;
266
+ viewController . view . addSubview ( nativeView ) ;
267
+ view . viewController = viewController ;
268
+ return viewController ;
269
+ }
267
270
}
271
+
272
+ throw new Error ( "Root should be either UIViewController or UIView" ) ;
268
273
}
269
274
270
275
global . __onLiveSync = function ( ) {
@@ -273,4 +278,4 @@ global.__onLiveSync = function () {
273
278
}
274
279
275
280
livesync ( ) ;
276
- }
281
+ }
0 commit comments