浏览代码

Fixes tabBarItem in navigationController return first child tabBarItem

yogevbd 6 年前
父节点
当前提交
ce9f431e6c
共有 2 个文件被更改,包括 21 次插入13 次删除
  1. 2
    2
      lib/ios/RNNNavigationController.m
  2. 19
    11
      lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m

+ 2
- 2
lib/ios/RNNNavigationController.m 查看文件

@@ -48,11 +48,11 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
48 48
 }
49 49
 
50 50
 - (UITabBarItem *)tabBarItem {
51
-	return self.viewControllers.lastObject.tabBarItem;
51
+	return self.viewControllers.firstObject.tabBarItem;
52 52
 }
53 53
 
54 54
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
55
-	return self.viewControllers.lastObject.supportedInterfaceOrientations;
55
+	return self.getCurrentChild.supportedInterfaceOrientations;
56 56
 }
57 57
 
58 58
 - (UINavigationController *)navigationController {

+ 19
- 11
lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m 查看文件

@@ -21,7 +21,7 @@
21 21
 	_vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:nil];
22 22
 	_vc3 = [UIViewController new];
23 23
 	
24
-	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
24
+	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
25 25
 }
26 26
 
27 27
 - (void)testInitWithLayoutInfo_shouldBindPresenter {
@@ -68,16 +68,16 @@
68 68
 	XCTAssertTrue(self.uut.interactivePopGestureRecognizer.enabled);
69 69
 }
70 70
 
71
-//- (void)testRootBackgroundImage {
72
-//	UIImage* rootBackgroundImage = [[UIImage alloc] init];
73
-//	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
74
-//	options.rootBackgroundImage = rootBackgroundImage;
75
-//	
76
-//	self.uut = [self createNavigationControllerWithOptions:options];
77
-//	[self.uut viewWillAppear:false];
78
-//	
79
-//	XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:rootBackgroundImage]);
80
-//}
71
+- (void)testRootBackgroundImage {
72
+	UIImage* rootBackgroundImage = [[UIImage alloc] init];
73
+	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
74
+	options.rootBackgroundImage = [[Image alloc] initWithValue:rootBackgroundImage];
75
+	
76
+	self.uut = [self createNavigationControllerWithOptions:options];
77
+	[self.uut onChildWillAppear];
78
+	
79
+	XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:rootBackgroundImage]);
80
+}
81 81
 
82 82
 - (void)testTopBarBackgroundClipToBounds_true {
83 83
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
@@ -98,6 +98,14 @@
98 98
 	XCTAssertFalse(self.uut.navigationController.navigationBar.clipsToBounds);
99 99
 }
100 100
 
101
+- (void)testTabBarItemShouldReturnFirstChildTabBarItem {
102
+	XCTAssertEqual(self.uut.tabBarItem, self.uut.childViewControllers.firstObject.tabBarItem);
103
+}
104
+
105
+- (void)testSupportedOrientationsShouldReturnCurrentChildSupportedOrientations {
106
+	XCTAssertEqual(self.uut.supportedInterfaceOrientations, self.uut.getCurrentChild.supportedInterfaceOrientations);
107
+}
108
+
101 109
 - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
102 110
 	return [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1] options:options presenter:[[RNNNavigationControllerPresenter alloc] init]];
103 111
 }