Browse Source

Fix bottomTab merging options with default (#5885)

When updating bottomTab options with mergeOptions - default options were not taken into account and therefore were not applied to the newly created tabBarItem
Yogev Ben David 4 years ago
parent
commit
513138ebd9
No account linked to committer's email address

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

3
 
3
 
4
 @interface Color : Param
4
 @interface Color : Param
5
 
5
 
6
++ (instancetype)withColor:(UIColor *)value;
7
+
6
 - (instancetype)initWithValue:(UIColor *)value;
8
 - (instancetype)initWithValue:(UIColor *)value;
7
 
9
 
8
 - (UIColor *)get;
10
 - (UIColor *)get;

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

8
 
8
 
9
 @implementation Color
9
 @implementation Color
10
 
10
 
11
++ (instancetype)withColor:(UIColor *)value {
12
+    return [[Color alloc] initWithValue:value];
13
+}
14
+
11
 - (instancetype)initWithValue:(UIColor *)value {
15
 - (instancetype)initWithValue:(UIColor *)value {
12
 	return [super initWithValue:value];
16
 	return [super initWithValue:value];
13
 }
17
 }

+ 11
- 16
lib/ios/RNNBasePresenter.m View File

116
 }
116
 }
117
 
117
 
118
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
118
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
119
-    UIViewController *viewController = self.boundViewController;
120
-    if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
119
+    UIViewController* viewController = self.boundViewController;
120
+    RNNNavigationOptions* withDefault = (RNNNavigationOptions *) [[resolvedOptions withDefault:_defaultOptions] overrideOptions:options];
121
+    
122
+    if (options.bottomTab.badge.hasValue) {
121
         [viewController setTabBarItemBadge:options.bottomTab.badge.get];
123
         [viewController setTabBarItemBadge:options.bottomTab.badge.get];
122
     }
124
     }
123
 
125
 
130
     }
132
     }
131
 
133
 
132
     if (options.bottomTab.text.hasValue) {
134
     if (options.bottomTab.text.hasValue) {
133
-        RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
134
-        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
135
+        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
135
         viewController.tabBarItem = tabItem;
136
         viewController.tabBarItem = tabItem;
136
     }
137
     }
137
 
138
 
138
     if (options.bottomTab.icon.hasValue) {
139
     if (options.bottomTab.icon.hasValue) {
139
-        RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
140
-        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
140
+        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
141
         viewController.tabBarItem = tabItem;
141
         viewController.tabBarItem = tabItem;
142
     }
142
     }
143
 
143
 
144
     if (options.bottomTab.selectedIcon.hasValue) {
144
     if (options.bottomTab.selectedIcon.hasValue) {
145
-        RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
146
-        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
145
+        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
147
         viewController.tabBarItem = tabItem;
146
         viewController.tabBarItem = tabItem;
148
     }
147
     }
149
 
148
 
150
     if (options.bottomTab.textColor.hasValue) {
149
     if (options.bottomTab.textColor.hasValue) {
151
-        RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
152
-        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
150
+        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
153
         viewController.tabBarItem = tabItem;
151
         viewController.tabBarItem = tabItem;
154
     }
152
     }
155
 
153
 
156
     if (options.bottomTab.selectedTextColor.hasValue) {
154
     if (options.bottomTab.selectedTextColor.hasValue) {
157
-        RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
158
-        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
155
+        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
159
         viewController.tabBarItem = tabItem;
156
         viewController.tabBarItem = tabItem;
160
     }
157
     }
161
 
158
 
162
     if (options.bottomTab.iconColor.hasValue) {
159
     if (options.bottomTab.iconColor.hasValue) {
163
-        RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
164
-        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
160
+        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
165
         viewController.tabBarItem = tabItem;
161
         viewController.tabBarItem = tabItem;
166
     }
162
     }
167
 
163
 
168
     if (options.bottomTab.selectedIconColor.hasValue) {
164
     if (options.bottomTab.selectedIconColor.hasValue) {
169
-        RNNNavigationOptions *buttonsResolvedOptions = (RNNNavigationOptions *) [resolvedOptions overrideOptions:options];
170
-        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
165
+        UITabBarItem *tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:withDefault.bottomTab];
171
         viewController.tabBarItem = tabItem;
166
         viewController.tabBarItem = tabItem;
172
     }
167
     }
173
 }
168
 }

+ 12
- 1
playground/ios/NavigationTests/RNNBasePresenterTest.m View File

96
 	XCTAssertTrue(_boundViewController.modalInPresentation);
96
 	XCTAssertTrue(_boundViewController.modalInPresentation);
97
 }
97
 }
98
 
98
 
99
-
99
+- (void)testMergeOptions_shouldSetTabBarItemColorWithDefaultOptions {
100
+	RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
101
+	defaultOptions.bottomTab.selectedIconColor = [Color withColor:UIColor.greenColor];
102
+	self.uut.defaultOptions = defaultOptions;
103
+	
104
+	RNNNavigationOptions* mergeOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
105
+	mergeOptions.bottomTab.text = [[Text alloc] initWithValue:@"title"];
106
+    OCMStub([self.mockBoundViewController parentViewController]).andReturn([UITabBarController new]);
107
+	
108
+    [self.uut mergeOptions:mergeOptions resolvedOptions:self.options];
109
+	XCTAssertEqual(self.uut.boundViewController.tabBarItem.title, @"title");
110
+}
100
 
111
 
101
 @end
112
 @end