Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27865] iOS: Titanium should add view controllers as children

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2021-01-15T20:09:23.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.0.0
ComponentsiOS
Labelsn/a
ReporterVijay Singh
AssigneeVijay Singh
Created2020-04-24T20:51:52.000+0000
Updated2021-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

FileDateSize
viewcontroller.png2020-04-24T20:52:51.000+00001480420

Comments

  1. Hans Knöchel 2020-10-17

    This also caused TIMOB-28109 / AC-6615 and should be fixed with high priority.
  2. Vijay Singh 2020-10-30

    PR - https://github.com/appcelerator/titanium_mobile/pull/12233
  3. Satyam Sekhri 2021-01-14

    FR Passed. Waiting for Jenkins build.
  4. Christopher Williams 2021-01-15

    Merged to master for 10.0.0 target.
  5. Samir Mohammed 2021-01-28

JSON Source