Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
513138ebd9
No account linked to committer's email address

+ 2
- 0
lib/ios/Color.h Dosyayı Görüntüle

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

+ 4
- 0
lib/ios/Color.m Dosyayı Görüntüle

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

+ 11
- 16
lib/ios/RNNBasePresenter.m Dosyayı Görüntüle

@@ -116,8 +116,10 @@
116 116
 }
117 117
 
118 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 123
         [viewController setTabBarItemBadge:options.bottomTab.badge.get];
122 124
     }
123 125
 
@@ -130,44 +132,37 @@
130 132
     }
131 133
 
132 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 136
         viewController.tabBarItem = tabItem;
136 137
     }
137 138
 
138 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 141
         viewController.tabBarItem = tabItem;
142 142
     }
143 143
 
144 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 146
         viewController.tabBarItem = tabItem;
148 147
     }
149 148
 
150 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 151
         viewController.tabBarItem = tabItem;
154 152
     }
155 153
 
156 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 156
         viewController.tabBarItem = tabItem;
160 157
     }
161 158
 
162 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 161
         viewController.tabBarItem = tabItem;
166 162
     }
167 163
 
168 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 166
         viewController.tabBarItem = tabItem;
172 167
     }
173 168
 }

+ 12
- 1
playground/ios/NavigationTests/RNNBasePresenterTest.m Dosyayı Görüntüle

@@ -96,6 +96,17 @@
96 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 112
 @end