Browse Source

Fix pushing screens to external components inside a modal (#5831)

* Fix pushing screens to external components inside modal
Yogev Ben David 4 years ago
parent
commit
4b14c8798b
No account linked to committer's email address

+ 0
- 4
lib/ios/RNNStackController.m View File

21
 	[self.presenter applyOptionsOnViewDidLayoutSubviews:self.resolveOptions];
21
 	[self.presenter applyOptionsOnViewDidLayoutSubviews:self.resolveOptions];
22
 }
22
 }
23
 
23
 
24
-- (UIViewController *)getCurrentChild {
25
-	return self.topViewController;
26
-}
27
-
28
 - (UINavigationController *)navigationController {
24
 - (UINavigationController *)navigationController {
29
 	return self;
25
 	return self;
30
 }
26
 }

+ 8
- 1
lib/ios/UIViewController+LayoutProtocol.m View File

80
 }
80
 }
81
 
81
 
82
 - (UIViewController *)getCurrentChild {
82
 - (UIViewController *)getCurrentChild {
83
+    for (UIViewController* childViewController in self.childViewControllers.reverseObjectEnumerator.allObjects) {
84
+        if (childViewController.layoutInfo) {
85
+            return childViewController;
86
+        }
87
+    }
88
+    
83
     return nil;
89
     return nil;
84
 }
90
 }
85
 
91
 
86
 - (UIViewController *)presentedComponentViewController {
92
 - (UIViewController *)presentedComponentViewController {
87
-    return self.getCurrentChild ? self.getCurrentChild.presentedComponentViewController : self;
93
+    UIViewController* currentChild = self.getCurrentChild;
94
+    return currentChild ? currentChild.presentedComponentViewController : self;
88
 }
95
 }
89
 
96
 
90
 - (UIViewController *)topMostViewController {
97
 - (UIViewController *)topMostViewController {

+ 3
- 0
playground/ios/NavigationTests/RNNModalManagerTest.m View File

43
 	_vc1 = [RNNComponentViewController new];
43
 	_vc1 = [RNNComponentViewController new];
44
 	_vc2 = [RNNComponentViewController new];
44
 	_vc2 = [RNNComponentViewController new];
45
 	_vc3 = [RNNComponentViewController new];
45
 	_vc3 = [RNNComponentViewController new];
46
+	_vc1.layoutInfo = [RNNLayoutInfo new];
47
+	_vc2.layoutInfo = [RNNLayoutInfo new];
48
+	_vc3.layoutInfo = [RNNLayoutInfo new];
46
 	_modalManager = [[MockModalManager alloc] init];
49
 	_modalManager = [[MockModalManager alloc] init];
47
 	_modalManager.topPresentedVC = [MockViewController new];
50
 	_modalManager.topPresentedVC = [MockViewController new];
48
 }
51
 }

+ 8
- 2
playground/ios/NavigationTests/RNNNavigationControllerTest.m View File

24
     [super setUp];
24
     [super setUp];
25
 	_eventEmitter = [OCMockObject niceMockForClass:[RNNEventEmitter class]];
25
 	_eventEmitter = [OCMockObject niceMockForClass:[RNNEventEmitter class]];
26
 	_creator = [[RNNTestRootViewCreator alloc] init];
26
 	_creator = [[RNNTestRootViewCreator alloc] init];
27
-	_vc1 = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNComponentPresenter alloc] init]] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
28
-	_vc2 = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNComponentPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
27
+	_vc1 = [[RNNComponentViewController alloc] initWithLayoutInfo:[RNNLayoutInfo new] rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNComponentPresenter alloc] init]] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
28
+	_vc2 = [[RNNComponentViewController alloc] initWithLayoutInfo:[RNNLayoutInfo new] rootViewCreator:nil eventEmitter:nil presenter:[[RNNComponentPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
29
 	_vc2Mock = [OCMockObject partialMockForObject:_vc2];
29
 	_vc2Mock = [OCMockObject partialMockForObject:_vc2];
30
 	_vc3 = [UIViewController new];
30
 	_vc3 = [UIViewController new];
31
 	_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
31
 	_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
53
 	XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
53
 	XCTAssertTrue(self.uut.getCurrentChild == self.uut.topViewController);
54
 }
54
 }
55
 
55
 
56
+- (void)testCurrentChild_shouldReturnLastChildWithLayoutInfo {
57
+	[self.uut addChildViewController:[UIViewController new]];
58
+	XCTAssertTrue(self.uut.getCurrentChild != self.uut.topViewController);
59
+	XCTAssertTrue(self.uut.getCurrentChild == self.uut.childViewControllers[self.uut.childViewControllers.count-2]);
60
+}
61
+
56
 - (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
62
 - (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
57
 	self.uut.getCurrentChild.resolveOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
63
 	self.uut.getCurrentChild.resolveOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
58
 	XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);
64
 	XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);

+ 4
- 4
playground/ios/NavigationTests/UIViewController+LayoutProtocolTest.m View File

52
 	RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
52
 	RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
53
 		defaultOptions.bottomTab.text = [[Text alloc] initWithValue:@"default text"];
53
 		defaultOptions.bottomTab.text = [[Text alloc] initWithValue:@"default text"];
54
 		defaultOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.blueColor];
54
 		defaultOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.blueColor];
55
-
56
-	UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:childOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
55
+	
56
+	UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:[RNNLayoutInfo new] creator:nil options:childOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
57
     RNNStackController* parent = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:parentOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:@[child]];
57
     RNNStackController* parent = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:parentOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:@[child]];
58
 
58
 
59
     XCTAssertEqual([parent getCurrentChild], child);
59
     XCTAssertEqual([parent getCurrentChild], child);
88
 
88
 
89
     RNNNavigationOptions * childOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
89
     RNNNavigationOptions * childOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
90
     childOptions.bottomTab.text = [[Text alloc] initWithValue:@"Child tab text"];
90
     childOptions.bottomTab.text = [[Text alloc] initWithValue:@"Child tab text"];
91
-    UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:childOptions defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:nil];
91
+    UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:[RNNLayoutInfo new] creator:nil options:childOptions defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:nil];
92
     RNNNavigationOptions * initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
92
     RNNNavigationOptions * initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
93
     initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"Initial title"];
93
     initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"Initial title"];
94
-    RNNStackController* uut = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:initialOptions defaultOptions:nil presenter:presenter eventEmitter:nil childViewControllers:@[child]];
94
+    RNNStackController* uut = [[RNNStackController alloc] initWithLayoutInfo:[RNNLayoutInfo new] creator:nil options:initialOptions defaultOptions:nil presenter:presenter eventEmitter:nil childViewControllers:@[child]];
95
     [parent addChildViewController:uut];
95
     [parent addChildViewController:uut];
96
 
96
 
97
 	[uut mergeOptions:toMerge];
97
 	[uut mergeOptions:toMerge];