Browse Source

Apply bottomTabs options after children added (#4994)

* Apply bottomTabs options after children added

* Fix unit tests
Yogev Ben David 5 years ago
parent
commit
2bddff390d
No account linked to committer's email address

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

14
 
14
 
15
 - (void)applyOptions:(RNNNavigationOptions *)options;
15
 - (void)applyOptions:(RNNNavigationOptions *)options;
16
 
16
 
17
+- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options;
18
+
17
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options;
19
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options;
18
 
20
 
19
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions;
21
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions;

+ 22
- 18
lib/ios/RNNBasePresenter.m View File

23
 }
23
 }
24
 
24
 
25
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
25
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
26
+	
27
+}
26
 
28
 
29
+- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options {
30
+	
27
 }
31
 }
28
 
32
 
29
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
33
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
30
 	UIViewController* viewController = self.bindedViewController;
34
 	UIViewController* viewController = self.bindedViewController;
31
-
35
+	
32
 	if (options.bottomTab.text.hasValue) {
36
 	if (options.bottomTab.text.hasValue) {
33
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
37
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
34
 		viewController.tabBarItem = tabItem;
38
 		viewController.tabBarItem = tabItem;
35
 	}
39
 	}
36
-
40
+	
37
 	if (options.bottomTab.icon.hasValue) {
41
 	if (options.bottomTab.icon.hasValue) {
38
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
42
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
39
 		viewController.tabBarItem = tabItem;
43
 		viewController.tabBarItem = tabItem;
40
 	}
44
 	}
41
-
45
+	
42
 	if (options.bottomTab.selectedIcon.hasValue) {
46
 	if (options.bottomTab.selectedIcon.hasValue) {
43
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
47
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
44
 		viewController.tabBarItem = tabItem;
48
 		viewController.tabBarItem = tabItem;
45
 	}
49
 	}
46
-
50
+	
47
 	if (options.bottomTab.badgeColor.hasValue) {
51
 	if (options.bottomTab.badgeColor.hasValue) {
48
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
52
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
49
 		viewController.tabBarItem = tabItem;
53
 		viewController.tabBarItem = tabItem;
50
 	}
54
 	}
51
-
55
+	
52
 	if (options.bottomTab.textColor.hasValue) {
56
 	if (options.bottomTab.textColor.hasValue) {
53
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
57
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
54
 		viewController.tabBarItem = tabItem;
58
 		viewController.tabBarItem = tabItem;
55
 	}
59
 	}
56
-
60
+	
57
 	if (options.bottomTab.iconColor.hasValue) {
61
 	if (options.bottomTab.iconColor.hasValue) {
58
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
62
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
59
 		viewController.tabBarItem = tabItem;
63
 		viewController.tabBarItem = tabItem;
60
 	}
64
 	}
61
-
65
+	
62
 	if (options.bottomTab.selectedTextColor.hasValue) {
66
 	if (options.bottomTab.selectedTextColor.hasValue) {
63
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
67
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
64
 		viewController.tabBarItem = tabItem;
68
 		viewController.tabBarItem = tabItem;
65
 	}
69
 	}
66
-
70
+	
67
 	if (options.bottomTab.selectedIconColor.hasValue) {
71
 	if (options.bottomTab.selectedIconColor.hasValue) {
68
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
72
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
69
 		viewController.tabBarItem = tabItem;
73
 		viewController.tabBarItem = tabItem;
72
 
76
 
73
 - (void)applyOptions:(RNNNavigationOptions *)options {
77
 - (void)applyOptions:(RNNNavigationOptions *)options {
74
 	UIViewController* viewController = self.bindedViewController;
78
 	UIViewController* viewController = self.bindedViewController;
75
-
79
+	
76
 	if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
80
 	if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
77
 		[viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
81
 		[viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
78
 	}
82
 	}
79
-
83
+	
80
 	if (options.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
84
 	if (options.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
81
 		[viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
85
 		[viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
82
 	}
86
 	}
87
 	if (newOptions.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
91
 	if (newOptions.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
88
 		[viewController rnn_setTabBarItemBadge:newOptions.bottomTab.badge.get];
92
 		[viewController rnn_setTabBarItemBadge:newOptions.bottomTab.badge.get];
89
 	}
93
 	}
90
-
94
+	
91
 	if (newOptions.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
95
 	if (newOptions.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
92
 		[viewController rnn_setTabBarItemBadgeColor:newOptions.bottomTab.badgeColor.get];
96
 		[viewController rnn_setTabBarItemBadgeColor:newOptions.bottomTab.badgeColor.get];
93
 	}
97
 	}
94
-
98
+	
95
 	if (newOptions.bottomTab.text.hasValue) {
99
 	if (newOptions.bottomTab.text.hasValue) {
96
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
100
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
97
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
101
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
98
 		viewController.tabBarItem = tabItem;
102
 		viewController.tabBarItem = tabItem;
99
 	}
103
 	}
100
-
104
+	
101
 	if (newOptions.bottomTab.icon.hasValue) {
105
 	if (newOptions.bottomTab.icon.hasValue) {
102
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
106
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
103
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
107
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
104
 		viewController.tabBarItem = tabItem;
108
 		viewController.tabBarItem = tabItem;
105
 	}
109
 	}
106
-
110
+	
107
 	if (newOptions.bottomTab.selectedIcon.hasValue) {
111
 	if (newOptions.bottomTab.selectedIcon.hasValue) {
108
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
112
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
109
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
113
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
110
 		viewController.tabBarItem = tabItem;
114
 		viewController.tabBarItem = tabItem;
111
 	}
115
 	}
112
-
116
+	
113
 	if (newOptions.bottomTab.textColor.hasValue) {
117
 	if (newOptions.bottomTab.textColor.hasValue) {
114
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
118
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
115
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
119
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
116
 		viewController.tabBarItem = tabItem;
120
 		viewController.tabBarItem = tabItem;
117
 	}
121
 	}
118
-
122
+	
119
 	if (newOptions.bottomTab.selectedTextColor.hasValue) {
123
 	if (newOptions.bottomTab.selectedTextColor.hasValue) {
120
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
124
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
121
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
125
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
122
 		viewController.tabBarItem = tabItem;
126
 		viewController.tabBarItem = tabItem;
123
 	}
127
 	}
124
-
128
+	
125
 	if (newOptions.bottomTab.iconColor.hasValue) {
129
 	if (newOptions.bottomTab.iconColor.hasValue) {
126
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
130
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
127
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
131
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
128
 		viewController.tabBarItem = tabItem;
132
 		viewController.tabBarItem = tabItem;
129
 	}
133
 	}
130
-
134
+	
131
 	if (newOptions.bottomTab.selectedIconColor.hasValue) {
135
 	if (newOptions.bottomTab.selectedIconColor.hasValue) {
132
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
136
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
133
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
137
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];

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

4
 	NSUInteger _currentTabIndex;
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
+
7
 - (id<UITabBarControllerDelegate>)delegate {
12
 - (id<UITabBarControllerDelegate>)delegate {
8
 	return self;
13
 	return self;
9
 }
14
 }

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

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

+ 2
- 2
lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m View File

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