[TIMOB-27865] iOS: Titanium should add view controllers as children
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2021-01-15T20:09:23.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 10.0.0 |
Components | iOS |
Labels | n/a |
Reporter | Vijay Singh |
Assignee | Vijay Singh |
Created | 2020-04-24T20:51:52.000+0000 |
Updated | 2021-01-28T13:12:51.000+0000 |
Description
Copied from [here](https://github.com/appcelerator/titanium_mobile/issues/11651) -
When adding windows to windows (e.g. using Titanium.UI.createNavigationWindow), Titanium ignores the [rules of view controller containment on iOS](https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html) and doesn't add view controllers as children.
The code responsible for calling the required methods has been commented out with a TODO: Revisit for almost 5 years (as of writing this issue):
[titanium_mobile/iphone/TitaniumKit/TitaniumKit/Sources/API/TiWindowProxy.m](https://github.com/appcelerator/titanium_mobile/blob/1afbbfc3f7fbc3f9f69580043d61ba4e75bf7127/iphone/TitaniumKit/TitaniumKit/Sources/API/TiWindowProxy.m#L150-L174)
- (void)attachViewToTopContainerController
{
UIViewController<TiControllerContainment> *topContainerController = [[[TiApp app] controller] topContainerController];
UIView *rootView = [topContainerController hostingView];
TiUIView *theView = [self view];
[rootView addSubview:theView];
[rootView bringSubviewToFront:theView];
// TODO: Revisit
/*
UIViewController<TiControllerContainment>* topContainerController = [[[TiApp app] controller] topContainerController];
UIView *rootView = [topContainerController hostingView];
UIViewController* thisViewController = [self hostingController];
UIView* theView = [thisViewController view];
[theView setFrame:[rootView bounds]];
[thisViewController willMoveToParentViewController:topContainerController];
[topContainerController addChildViewController:thisViewController];
[rootView addSubview:theView];
[rootView bringSubviewToFront:theView];
[thisViewController didMoveToParentViewController:topContainerController];
*/
}
This causes issues in view-controller-backed modules (such as PSPDFKit), especially during view controller presentation. UIKit eve logs a warning message about this:
"Presenting view controllers on detached view controllers is discouraged."
Steps to reproduce-
Create a plain window and a navigation window. Run the app and inspect the view hierarchy.
var window = Titanium.UI.createWindow({
backgroundColor: "white",
})
var navigationWindow = Titanium.UI.createNavigationWindow({
window: window,
})
navigationWindow.open()
Expected behavior -
Every view controller in the hierarchy (except for TiRootViewController) has a correctly set parent view controller.
Actual behavior -
UINavigationController managed by Titanium.UI.NavigationWindow is detached and has no parent view controller. See attached image view "controller.png"
Attachments
File | Date | Size |
---|---|---|
viewcontroller.png | 2020-04-24T20:52:51.000+0000 | 1480420 |
This also caused TIMOB-28109 / AC-6615 and should be fixed with high priority.
PR - https://github.com/appcelerator/titanium_mobile/pull/12233
FR Passed. Waiting for Jenkins build.
Merged to master for 10.0.0 target.