Skip to content

Commit 63ab46e

Browse files
Hristo HristovHristo Hristov
Hristo Hristov
authored and
Hristo Hristov
committed
Layout improvements
1 parent 33cd058 commit 63ab46e

File tree

4 files changed

+249
-129
lines changed

4 files changed

+249
-129
lines changed

tns-core-modules/application/application.ios.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class IOSApplication implements IOSApplicationDefinition {
118118
this._rootView = rootView;
119119
const controller = getViewController(rootView);
120120
this._window.rootViewController = controller;
121+
rootView._setupAsRootView({});
121122
this._window.makeKeyAndVisible();
122123
}
123124

@@ -199,8 +200,7 @@ function createRootView(v?: View) {
199200
// try to navigate to the mainEntry (if specified)
200201
if (mainEntry) {
201202
if (createRootFrame) {
202-
const frame = new Frame();
203-
rootView = frame;
203+
const frame = rootView = new Frame();
204204
frame.navigate(mainEntry);
205205
} else {
206206
rootView = createViewFromEntry(mainEntry);
@@ -211,7 +211,6 @@ function createRootView(v?: View) {
211211
}
212212
}
213213

214-
rootView._setupAsRootView({});
215214
return rootView;
216215
}
217216

@@ -230,6 +229,7 @@ export function start(entry?: string | NavigationEntry) {
230229
// Normal NativeScript app will need UIApplicationMain.
231230
UIApplicationMain(0, null, null, iosApp && iosApp.delegate ? NSStringFromClass(<any>iosApp.delegate) : NSStringFromClass(Responder));
232231
} else {
232+
// TODO: this rootView should be held alive until rootController dismissViewController is called.
233233
const rootView = createRootView();
234234
if (rootView) {
235235
// Attach to the existing iOS app
@@ -238,6 +238,7 @@ export function start(entry?: string | NavigationEntry) {
238238
const rootController = window.rootViewController;
239239
if (rootController) {
240240
const controller = getViewController(rootView);
241+
rootView._setupAsRootView({});
241242
rootController.presentViewControllerAnimatedCompletion(controller, true, null);
242243
}
243244
}
@@ -258,13 +259,17 @@ function getViewController(view: View): UIViewController {
258259
let viewController: UIViewController = view.viewController || view.ios;
259260
if (viewController instanceof UIViewController) {
260261
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;
265262
} 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+
}
267270
}
271+
272+
throw new Error("Root should be either UIViewController or UIView");
268273
}
269274

270275
global.__onLiveSync = function () {
@@ -273,4 +278,4 @@ global.__onLiveSync = function () {
273278
}
274279

275280
livesync();
276-
}
281+
}

0 commit comments

Comments
 (0)