Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions tns-core-modules/application/application.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ class IOSApplication implements IOSApplicationDefinition {
this._rootView._onRootViewReset();
}
const rootView = createRootView(view);
const controller = getViewController(rootView);

this._rootView = rootView;

if (createRootFrame.value) {
Expand All @@ -236,7 +238,7 @@ class IOSApplication implements IOSApplicationDefinition {
// setup view as styleScopeHost
rootView._setupAsRootView({});
}
const controller = getViewController(rootView);
setViewControllerView(rootView);
const haveController = this._window.rootViewController !== null;
this._window.rootViewController = controller;
if (!haveController) {
Expand Down Expand Up @@ -339,16 +341,25 @@ function getViewController(view: View): UIViewController {
if (viewController instanceof UIViewController) {
return viewController;
} else {
const nativeView = view.ios || view.nativeViewProtected;
if (nativeView instanceof UIView) {
viewController = iosView.UILayoutViewController.initWithOwner(new WeakRef(view)) as UIViewController;
viewController.view.addSubview(nativeView);
view.viewController = viewController;
return viewController;
}
// We set UILayoutViewController dynamically to the root view if it doesn't have a view controller
// At the moment the root view doesn't have its native view created. We set it in the setViewControllerView func
viewController = iosView.UILayoutViewController.initWithOwner(new WeakRef(view)) as UIViewController;
view.viewController = viewController;
return viewController;
}
}

function setViewControllerView(view: View): void {
Comment thread
MartoYankov marked this conversation as resolved.
const viewController: UIViewController = view.viewController || view.ios;
const nativeView = view.ios || view.nativeViewProtected;

throw new Error("Root should be either UIViewController or UIView");
if (!nativeView || !viewController) {
throw new Error("Root should be either UIViewController or UIView");
}

if (viewController instanceof iosView.UILayoutViewController) {
viewController.view.addSubview(nativeView);
}
}

global.__onLiveSync = function () {
Expand Down