Browse Source

Fix bottomTabs.currentTabIndex, Closes #5012 (#5013)

* Fix bottomTabs.currentTabIndex, Closes #5012

* Set currentTabIndex on init
Yogev Ben David 5 years ago
parent
commit
0e888fb65a
No account linked to committer's email address

+ 0
- 2
lib/ios/RNNBasePresenter.h View File

@@ -14,8 +14,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
14 14
 
15 15
 - (void)applyOptions:(RNNNavigationOptions *)options;
16 16
 
17
-- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options;
18
-
19 17
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options;
20 18
 
21 19
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions;

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

@@ -19,10 +19,6 @@
19 19
 	
20 20
 }
21 21
 
22
-- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options {
23
-	
24
-}
25
-
26 22
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
27 23
 	UIViewController* viewController = self.bindedViewController;
28 24
 	

+ 0
- 5
lib/ios/RNNTabBarController.m View File

@@ -4,11 +4,6 @@
4 4
 	NSUInteger _currentTabIndex;
5 5
 }
6 6
 
7
-- (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
8
-	[super setViewControllers:viewControllers];
9
-	[self.presenter applyOptionsOnSetViewControllers:self.resolveOptions];
10
-}
11
-
12 7
 - (id<UITabBarControllerDelegate>)delegate {
13 8
 	return self;
14 9
 }

+ 1
- 1
lib/ios/RNNTabBarPresenter.m View File

@@ -3,7 +3,7 @@
3 3
 
4 4
 @implementation RNNTabBarPresenter
5 5
 
6
-- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options {
6
+- (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
7 7
 	UITabBarController* tabBarController = self.bindedViewController;
8 8
 	[tabBarController rnn_setCurrentTabIndex:[options.bottomTabs.currentTabIndex getWithDefaultValue:0]];
9 9
 }

+ 10
- 0
lib/ios/ReactNativeNavigationTests/RNNTabBarControllerTest.m View File

@@ -153,4 +153,14 @@
153 153
 	XCTAssertTrue(uut.selectedIndex == 1);
154 154
 }
155 155
 
156
+- (void)testSetSelectedIndex_ShouldSetSelectedIndexWithCurrentTabIndex {
157
+	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
158
+	options.bottomTabs.currentTabIndex = [[IntNumber alloc] initWithValue:@(1)];
159
+
160
+	RNNRootViewController* vc = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:nil options:nil defaultOptions:nil];
161
+	RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil creator:nil options:options defaultOptions:nil presenter:[RNNTabBarPresenter new] eventEmitter:nil childViewControllers:@[[UIViewController new], vc]];
162
+	
163
+	XCTAssertTrue(uut.selectedIndex == 1);
164
+}
165
+
156 166
 @end

+ 0
- 8
lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m View File

@@ -54,13 +54,5 @@
54 54
 	[self.bindedViewController verify];
55 55
 }
56 56
 
57
-- (void)testApplyOptions_shouldApplyOptionsOnSetViewControllers {
58
-	RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
59
-	initialOptions.bottomTabs.currentTabIndex = [[IntNumber alloc] initWithValue:@(1)];
60
-	[[self.bindedViewController expect] rnn_setCurrentTabIndex:1];
61
-	
62
-	[self.uut applyOptionsOnSetViewControllers:initialOptions];
63
-	[self.bindedViewController verify];
64
-}
65 57
 
66 58
 @end