Browse Source

Fix setting bottomTabs.currentTabIndex on bottomTabs init (#4457)

Yogev Ben David 6 years ago
parent
commit
631e7dbd55
No account linked to committer's email address

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

@@ -31,6 +31,7 @@
31 31
 	self.presenter = presenter;
32 32
 	[self.presenter bindViewController:self];
33 33
 	[self setViewControllers:childViewControllers];
34
+	[self.presenter applyOptionsOnInit:self.options];
34 35
 	
35 36
 	return self;
36 37
 }

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

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

+ 10
- 1
lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m View File

@@ -33,7 +33,7 @@
33 33
 	[self.bindedViewController verify];
34 34
 }
35 35
 
36
-- (void)testApplyOptions_shouldSetInitialOptions {
36
+- (void)testApplyOptions_shouldApplyOptions {
37 37
 	RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
38 38
 	initialOptions.bottomTabs.testID = [[Text alloc] initWithValue:@"testID"];
39 39
 	initialOptions.bottomTabs.backgroundColor = [[Color alloc] initWithValue:[UIColor redColor]];
@@ -53,4 +53,13 @@
53 53
 	[self.bindedViewController verify];
54 54
 }
55 55
 
56
+- (void)testApplyOptions_shouldApplyOptionsOnInit {
57
+	RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
58
+	initialOptions.bottomTabs.currentTabIndex = [[IntNumber alloc] initWithValue:@(1)];
59
+	[[self.bindedViewController expect] rnn_setCurrentTabIndex:1];
60
+	
61
+	[self.uut applyOptionsOnInit:initialOptions];
62
+	[self.bindedViewController verify];
63
+}
64
+
56 65
 @end