Просмотр исходного кода

Revert "setStyle to style the according TabBar (#2224)" (#2276)

This reverts commit 076ee7311e.
Guy Carmeli 7 лет назад
Родитель
Сommit
2c9ba1d385
No account linked to committer's email address

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java Просмотреть файл

@@ -229,8 +229,6 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
229 229
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
230 230
             screenStacks[i].updateScreenStyle(screenInstanceId, styleParams);
231 231
         }
232
-
233
-        bottomTabs.updateTabStyle(styleParams);
234 232
     }
235 233
 
236 234
     @Override

+ 0
- 8
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java Просмотреть файл

@@ -126,14 +126,6 @@ public class StyleParamsParser {
126 126
         result.titleBarButtonFontFamily = new StyleParams.Font();
127 127
         result.titleBarHeight = -1;
128 128
         result.screenAnimationType = "slide-up";
129
-
130
-        result.bottomTabsColor = getDefaultBottomTabsColor();
131
-        result.bottomTabsButtonColor = getDefaultBottomTabsButtonColor();
132
-        result.selectedBottomTabsButtonColor = getDefaultSelectedBottomTabsButtonColor();
133
-
134
-        result.bottomTabBadgeTextColor = getBottomTabBadgeTextColor();
135
-        result.bottomTabBadgeBackgroundColor = getBottomTabBadgeBackgroundColor();
136
-
137 129
         return result;
138 130
     }
139 131
 

+ 26
- 25
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java Просмотреть файл

@@ -2,7 +2,6 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.graphics.Color;
5
-import android.os.Bundle;
6 5
 import android.text.TextUtils;
7 6
 
8 7
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
@@ -11,7 +10,6 @@ import com.reactnativenavigation.animation.VisibilityAnimator;
11 10
 import com.reactnativenavigation.params.AppStyle;
12 11
 import com.reactnativenavigation.params.ScreenParams;
13 12
 import com.reactnativenavigation.params.StyleParams;
14
-import com.reactnativenavigation.params.parsers.StyleParamsParser;
15 13
 import com.reactnativenavigation.utils.ViewUtils;
16 14
 import com.reactnativenavigation.views.utils.Constants;
17 15
 
@@ -26,7 +24,7 @@ public class BottomTabs extends AHBottomNavigation {
26 24
         setForceTint(true);
27 25
         setId(ViewUtils.generateViewId());
28 26
         createVisibilityAnimator();
29
-        setStyle(AppStyle.appStyle);
27
+        setStyle();
30 28
         setFontFamily();
31 29
     }
32 30
 
@@ -40,13 +38,20 @@ public class BottomTabs extends AHBottomNavigation {
40 38
         setTitlesDisplayState();
41 39
     }
42 40
 
43
-    public void updateTabStyle(Bundle styleParams) {
44
-        StyleParams parsedStyleParams = new StyleParamsParser(styleParams).parse();
45
-        this.setStyleFromScreen(parsedStyleParams);
46
-    }
47
-
48 41
     public void setStyleFromScreen(StyleParams params) {
49
-        this.setStyle(params);
42
+        if (params.bottomTabsColor.hasColor()) {
43
+            setBackgroundColor(params.bottomTabsColor);
44
+        }
45
+        if (params.bottomTabsButtonColor.hasColor()) {
46
+            if (getInactiveColor() != params.bottomTabsButtonColor.getColor()) {
47
+                setInactiveColor(params.bottomTabsButtonColor.getColor());
48
+            }
49
+        }
50
+        if (params.selectedBottomTabsButtonColor.hasColor()) {
51
+            if (getAccentColor() != params.selectedBottomTabsButtonColor.getColor()) {
52
+                setAccentColor(params.selectedBottomTabsButtonColor.getColor());
53
+            }
54
+        }
50 55
 
51 56
         setVisibility(params.bottomTabsHidden, true);
52 57
     }
@@ -127,27 +132,23 @@ public class BottomTabs extends AHBottomNavigation {
127 132
                 Constants.BOTTOM_TABS_HEIGHT);
128 133
     }
129 134
 
130
-    private void setStyle(StyleParams params) {
131
-        if (params.bottomTabBadgeBackgroundColor.hasColor()) {
135
+    private void setStyle() {
136
+        if (hasBadgeBackgroundColor()) {
132 137
             setNotificationBackgroundColor(AppStyle.appStyle.bottomTabBadgeBackgroundColor.getColor());
133 138
         }
134
-        if (params.bottomTabBadgeTextColor.hasColor()) {
139
+        if (hasBadgeTextColor()) {
135 140
             setNotificationTextColor(AppStyle.appStyle.bottomTabBadgeTextColor.getColor());
136 141
         }
142
+    }
137 143
 
138
-        if (params.bottomTabsColor.hasColor()) {
139
-            setBackgroundColor(params.bottomTabsColor);
140
-        }
141
-        if (params.bottomTabsButtonColor.hasColor()) {
142
-            if (getInactiveColor() != params.bottomTabsButtonColor.getColor()) {
143
-                setInactiveColor(params.bottomTabsButtonColor.getColor());
144
-            }
145
-        }
146
-        if (params.selectedBottomTabsButtonColor.hasColor()) {
147
-            if (getAccentColor() != params.selectedBottomTabsButtonColor.getColor()) {
148
-                setAccentColor(params.selectedBottomTabsButtonColor.getColor());
149
-            }
150
-        }
144
+    private boolean hasBadgeTextColor() {
145
+        return AppStyle.appStyle.bottomTabBadgeTextColor != null &&
146
+               AppStyle.appStyle.bottomTabBadgeTextColor.hasColor();
147
+    }
148
+
149
+    private boolean hasBadgeBackgroundColor() {
150
+        return AppStyle.appStyle.bottomTabBadgeBackgroundColor != null &&
151
+               AppStyle.appStyle.bottomTabBadgeBackgroundColor.hasColor();
151 152
     }
152 153
 
153 154
     private void setFontFamily() {

+ 17
- 17
ios/RCCNavigationController.m Просмотреть файл

@@ -337,23 +337,23 @@ NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSO
337 337
   // setStyle
338 338
   if ([performAction isEqualToString:@"setStyle"])
339 339
   {
340
-    for (UIViewController *viewController in self.viewControllers) {
341
-      if ([viewController isKindOfClass:[RCCViewController class]])
342
-      {
343
-        RCCViewController *rccViewController = (RCCViewController*)viewController;
344
-        
345
-        NSDictionary *navigatorStyle = [[NSDictionary alloc] initWithDictionary:actionParams copyItems:YES];
346
-        NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:rccViewController.navigatorStyle];
347
-        
348
-        // there are a few styles that we don't want to remember from our parent (they should be local)
349
-        [mergedStyle setValuesForKeysWithDictionary:navigatorStyle];
350
-        navigatorStyle = mergedStyle;
351
-        
352
-        rccViewController.navigatorStyle = navigatorStyle;
353
-        
354
-        [rccViewController setStyleOnInit];
355
-        [rccViewController updateStyle];
356
-      }
340
+    
341
+    NSDictionary *navigatorStyle = actionParams;
342
+    
343
+    // merge the navigatorStyle of our parent
344
+    if ([self.topViewController isKindOfClass:[RCCViewController class]])
345
+    {
346
+      RCCViewController *parent = (RCCViewController*)self.topViewController;
347
+      NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:parent.navigatorStyle];
348
+      
349
+      // there are a few styles that we don't want to remember from our parent (they should be local)
350
+      [mergedStyle setValuesForKeysWithDictionary:navigatorStyle];
351
+      navigatorStyle = mergedStyle;
352
+      
353
+      parent.navigatorStyle = navigatorStyle;
354
+      
355
+      [parent setStyleOnInit];
356
+      [parent updateStyle];
357 357
     }
358 358
   }
359 359
 }

+ 0
- 1
ios/RCCTabBarController.h Просмотреть файл

@@ -5,6 +5,5 @@
5 5
 
6 6
 - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge;
7 7
 - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge completion:(void (^)(void))completion;
8
-+ (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1;
9 8
 
10 9
 @end

+ 3
- 3
ios/RCCTabBarController.m Просмотреть файл

@@ -55,7 +55,7 @@
55 55
   return YES;
56 56
 }
57 57
 
58
-+ (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1
58
+- (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1
59 59
 {
60 60
   UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
61 61
   CGContextRef context = UIGraphicsGetCurrentContext();
@@ -159,7 +159,7 @@
159 159
       iconImage = [RCTConvert UIImage:icon];
160 160
       if (buttonColor)
161 161
       {
162
-        iconImage = [[RCCTabBarController image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
162
+        iconImage = [[self image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
163 163
       }
164 164
     }
165 165
     UIImage *iconImageSelected = nil;
@@ -327,7 +327,7 @@
327 327
       if (icon && icon != (id)[NSNull null])
328 328
       {
329 329
         iconImage = [RCTConvert UIImage:icon];
330
-        iconImage = [[RCCTabBarController image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
330
+        iconImage = [[self image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
331 331
         viewController.tabBarItem.image = iconImage;
332 332
       }
333 333
       

+ 4
- 88
ios/RCCViewController.m Просмотреть файл

@@ -484,95 +484,11 @@ const NSInteger TRANSPARENT_NAVBAR_TAG = 78264803;
484 484
     [viewController setNeedsStatusBarAppearanceUpdate];
485 485
   }
486 486
   
487
-  if (viewController.tabBarController && viewController.tabBarController.tabBar != (id)[NSNull null]) {
487
+  NSNumber *tabBarHidden = self.navigatorStyle[@"tabBarHidden"];
488
+  BOOL tabBarHiddenBool = tabBarHidden ? [tabBarHidden boolValue] : NO;
489
+  if (tabBarHiddenBool) {
488 490
     UITabBar *tabBar = viewController.tabBarController.tabBar;
489
-    
490
-    if (tabBar && tabBar != (id)[NSNull null]) {
491
-      UIColor *buttonColor = nil;
492
-      UIColor *selectedButtonColor = nil;
493
-      UIColor *labelColor = nil;
494
-      UIColor *selectedLabelColor = nil;
495
-      
496
-      NSNumber *tabBarHidden = self.navigatorStyle[@"tabBarHidden"];
497
-      BOOL tabBarHiddenBool = tabBarHidden ? [tabBarHidden boolValue] : NO;
498
-      if (tabBarHiddenBool) {
499
-        tabBar.transform = CGAffineTransformMakeTranslation(0, tabBar.frame.size.height);
500
-      }
501
-      
502
-      NSString *tabBarButtonColor = self.navigatorStyle[@"tabBarButtonColor"];
503
-      NSString *tabBarSelectedButtonColor = self.navigatorStyle[@"tabBarSelectedButtonColor"];
504
-      
505
-      if (tabBarButtonColor)
506
-      {
507
-        buttonColor = tabBarButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarButtonColor] : nil;
508
-        
509
-        if (tabBarSelectedButtonColor) {
510
-          selectedButtonColor = tabBarSelectedButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedButtonColor] : nil;
511
-          
512
-          tabBar.tintColor = selectedLabelColor = selectedButtonColor;
513
-          tabBar.unselectedItemTintColor = labelColor = buttonColor;
514
-        }
515
-        else {
516
-          tabBar.tintColor = labelColor = buttonColor;
517
-        }
518
-      }
519
-      else if (tabBarSelectedButtonColor) {
520
-        selectedButtonColor = tabBarSelectedButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedButtonColor] : nil;
521
-        tabBar.tintColor = selectedLabelColor = selectedButtonColor;
522
-      }
523
-      
524
-      NSString *tabBarLabelColor = self.navigatorStyle[@"tabBarLabelColor"];
525
-      if(tabBarLabelColor) {
526
-        UIColor *color = tabBarLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarLabelColor] : nil;
527
-        labelColor = color;
528
-      }
529
-      NSString *tabBarSelectedLabelColor = self.navigatorStyle[@"tabBarSelectedLabelColor"];
530
-      if(tabBarLabelColor) {
531
-        UIColor *color = tabBarSelectedLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedLabelColor] : nil;
532
-        selectedLabelColor = color;
533
-      }
534
-      
535
-      NSString *tabBarBackgroundColor = self.navigatorStyle[@"tabBarBackgroundColor"];
536
-      if (tabBarBackgroundColor)
537
-      {
538
-        UIColor *color = tabBarBackgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarBackgroundColor] : nil;
539
-        tabBar.barTintColor = color;
540
-      }
541
-      
542
-      NSNumber *tabBarTranslucent = self.navigatorStyle[@"tabBarTranslucent"];
543
-      if (tabBarTranslucent)
544
-      {
545
-        BOOL tabBarTranslucentBool = tabBarTranslucent ? [tabBarTranslucent boolValue] : NO;
546
-        tabBar.translucent = tabBarTranslucentBool;
547
-      }
548
-      
549
-      NSNumber *tabBarHideShadow = self.navigatorStyle[@"tabBarHideShadow"];
550
-      if (tabBarHideShadow)
551
-      {
552
-        BOOL tabBarHideShadowBool = tabBarHideShadow ? [tabBarHideShadow boolValue] : NO;
553
-        tabBar.clipsToBounds = tabBarHideShadowBool ? YES : NO;
554
-      }
555
-      
556
-      for (UIViewController *tabViewController in [viewController.tabBarController viewControllers]) {
557
-        NSMutableDictionary *unselectedAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"tabBarText" baseFont:[UIFont systemFontOfSize:10]];
558
-        if (!unselectedAttributes[NSForegroundColorAttributeName] && labelColor) {
559
-          unselectedAttributes[NSForegroundColorAttributeName] = labelColor;
560
-        }
561
-        [tabViewController.tabBarItem setTitleTextAttributes:unselectedAttributes forState:UIControlStateNormal];
562
-        
563
-        
564
-        NSMutableDictionary *selectedAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"tabBarSelectedText" baseFont:[UIFont systemFontOfSize:10]];
565
-        if (!selectedAttributes[NSForegroundColorAttributeName] && selectedLabelColor) {
566
-          selectedAttributes[NSForegroundColorAttributeName] = selectedLabelColor;
567
-        }
568
-        [tabViewController.tabBarItem setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
569
-        
570
-        if (buttonColor)
571
-        {
572
-          tabViewController.tabBarItem.image = [[RCCTabBarController image:tabViewController.tabBarItem.image withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
573
-        }
574
-      }
575
-    }
491
+    tabBar.transform = CGAffineTransformMakeTranslation(0, tabBar.frame.size.height);
576 492
   }
577 493
 
578 494
   NSNumber *navBarHidden = self.navigatorStyle[@"navBarHidden"];