Browse Source

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

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

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

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

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

@@ -80,11 +80,18 @@
80 80
 }
81 81
 
82 82
 - (UIViewController *)getCurrentChild {
83
+    for (UIViewController* childViewController in self.childViewControllers.reverseObjectEnumerator.allObjects) {
84
+        if (childViewController.layoutInfo) {
85
+            return childViewController;
86
+        }
87
+    }
88
+    
83 89
     return nil;
84 90
 }
85 91
 
86 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 97
 - (UIViewController *)topMostViewController {

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

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

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

@@ -24,8 +24,8 @@
24 24
     [super setUp];
25 25
 	_eventEmitter = [OCMockObject niceMockForClass:[RNNEventEmitter class]];
26 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 29
 	_vc2Mock = [OCMockObject partialMockForObject:_vc2];
30 30
 	_vc3 = [UIViewController new];
31 31
 	_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
@@ -53,6 +53,12 @@
53 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 62
 - (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
57 63
 	self.uut.getCurrentChild.resolveOptions.statusBar.style = [[Text alloc] initWithValue:@"light"];
58 64
 	XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);

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

@@ -52,8 +52,8 @@
52 52
 	RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
53 53
 		defaultOptions.bottomTab.text = [[Text alloc] initWithValue:@"default text"];
54 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 57
     RNNStackController* parent = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:parentOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:@[child]];
58 58
 
59 59
     XCTAssertEqual([parent getCurrentChild], child);
@@ -88,10 +88,10 @@
88 88
 
89 89
     RNNNavigationOptions * childOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
90 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 92
     RNNNavigationOptions * initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
93 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 95
     [parent addChildViewController:uut];
96 96
 
97 97
 	[uut mergeOptions:toMerge];