瀏覽代碼

Revert "SetStyle fix (#2539)"

This reverts commit 883dcfe49f.
yogevbd 6 年之前
父節點
當前提交
bb3dff9ded

+ 4
- 7
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java 查看文件

@@ -16,7 +16,6 @@ import com.facebook.react.bridge.Callback;
16 16
 import com.facebook.react.bridge.Promise;
17 17
 import com.facebook.react.bridge.WritableMap;
18 18
 import com.reactnativenavigation.NavigationApplication;
19
-import com.reactnativenavigation.events.Event;
20 19
 import com.reactnativenavigation.events.EventBus;
21 20
 import com.reactnativenavigation.events.ScreenChangedEvent;
22 21
 import com.reactnativenavigation.params.ActivityParams;
@@ -230,8 +229,6 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
230 229
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
231 230
             screenStacks[i].updateScreenStyle(screenInstanceId, styleParams);
232 231
         }
233
-
234
-        bottomTabs.setStyleFromScreen(this.getCurrentScreen().getStyleParams());
235 232
     }
236 233
 
237 234
     @Override
@@ -363,7 +360,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
363 360
 
364 361
     private boolean hasBackgroundColor(StyleParams params) {
365 362
         return params.screenBackgroundColor != null &&
366
-                params.screenBackgroundColor.hasColor();
363
+            params.screenBackgroundColor.hasColor();
367 364
     }
368 365
 
369 366
     private void setStyleFromScreen(StyleParams params) {
@@ -394,7 +391,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
394 391
         performOnStack(params.getNavigatorId(), new Task<ScreenStack>() {
395 392
             @Override
396 393
             public void run(ScreenStack stack) {
397
-                stack.pop(params.animateScreenTransitions, params.timestamp, new ScreenStack.OnScreenPop() {
394
+            stack.pop(params.animateScreenTransitions, params.timestamp, new ScreenStack.OnScreenPop() {
398 395
                     @Override
399 396
                     public void onScreenPopAnimationEnd() {
400 397
                         setBottomTabsStyleFromCurrentScreen();
@@ -453,8 +450,8 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
453 450
             task.run(screenStack);
454 451
         } catch (ScreenStackNotFoundException e) {
455 452
             Log.e("Navigation", "Could not perform action on stack [" + navigatorId + "]." +
456
-                    "This should not have happened, it probably means a navigator action" +
457
-                    "was called from an unmounted tab.");
453
+                                      "This should not have happened, it probably means a navigator action" +
454
+                                      "was called from an unmounted tab.");
458 455
         }
459 456
     }
460 457
 

+ 0
- 8
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java 查看文件

@@ -131,14 +131,6 @@ public class StyleParamsParser {
131 131
         result.titleBarHeight = -1;
132 132
         result.screenAnimationType = "slide-up";
133 133
         result.drawUnderStatusBar = false;
134
-
135
-        result.bottomTabsColor = getDefaultBottomTabsColor();
136
-        result.bottomTabsButtonColor = getDefaultBottomTabsButtonColor();
137
-        result.selectedBottomTabsButtonColor = getDefaultSelectedBottomTabsButtonColor();
138
-
139
-        result.bottomTabBadgeTextColor = getBottomTabBadgeTextColor();
140
-        result.bottomTabBadgeBackgroundColor = getBottomTabBadgeBackgroundColor();
141
-
142 134
         return result;
143 135
     }
144 136
 

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java 查看文件

@@ -216,7 +216,7 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
216 216
     }
217 217
 
218 218
     public void setTitleBarTitle(String title) {
219
-        topBar.setTitle(title, styleParams);
219
+       topBar.setTitle(title, styleParams);
220 220
     }
221 221
 
222 222
     public void setTitleBarSubtitle(String subtitle) {

+ 28
- 22
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
 
@@ -23,17 +21,17 @@ public class BottomTabs extends AHBottomNavigation {
23 21
 
24 22
     public BottomTabs(Context context) {
25 23
         super(context);
26
-
27 24
         setForceTint(true);
28 25
         setId(ViewUtils.generateViewId());
29 26
         createVisibilityAnimator();
30
-        setStyle(AppStyle.appStyle);
27
+        setStyle();
31 28
         setFontFamily();
32 29
     }
33 30
 
34 31
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
35 32
         for (ScreenParams screenParams : params) {
36
-            AHBottomNavigationItem item = new AHBottomNavigationItem(screenParams.tabLabel, screenParams.tabIcon, Color.GRAY);
33
+            AHBottomNavigationItem item = new AHBottomNavigationItem(screenParams.tabLabel, screenParams.tabIcon,
34
+                    Color.GRAY);
37 35
             addItem(item);
38 36
             setOnTabSelectedListener(onTabSelectedListener);
39 37
         }
@@ -41,7 +39,19 @@ public class BottomTabs extends AHBottomNavigation {
41 39
     }
42 40
 
43 41
     public void setStyleFromScreen(StyleParams params) {
44
-        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
+        }
45 55
 
46 56
         setVisibility(params.bottomTabsHidden, true);
47 57
     }
@@ -122,27 +132,23 @@ public class BottomTabs extends AHBottomNavigation {
122 132
                 Constants.BOTTOM_TABS_HEIGHT);
123 133
     }
124 134
 
125
-    private void setStyle(StyleParams params) {
126
-        if (params.bottomTabBadgeBackgroundColor.hasColor()) {
135
+    private void setStyle() {
136
+        if (hasBadgeBackgroundColor()) {
127 137
             setNotificationBackgroundColor(AppStyle.appStyle.bottomTabBadgeBackgroundColor.getColor());
128 138
         }
129
-        if (params.bottomTabBadgeTextColor.hasColor()) {
139
+        if (hasBadgeTextColor()) {
130 140
             setNotificationTextColor(AppStyle.appStyle.bottomTabBadgeTextColor.getColor());
131 141
         }
142
+    }
132 143
 
133
-        if (params.bottomTabsColor.hasColor()) {
134
-            setBackgroundColor(params.bottomTabsColor);
135
-        }
136
-        if (params.bottomTabsButtonColor.hasColor()) {
137
-            if (getInactiveColor() != params.bottomTabsButtonColor.getColor()) {
138
-                setInactiveColor(params.bottomTabsButtonColor.getColor());
139
-            }
140
-        }
141
-        if (params.selectedBottomTabsButtonColor.hasColor()) {
142
-            if (getAccentColor() != params.selectedBottomTabsButtonColor.getColor()) {
143
-                setAccentColor(params.selectedBottomTabsButtonColor.getColor());
144
-            }
145
-        }
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();
146 152
     }
147 153
 
148 154
     private void setFontFamily() {

+ 17
- 19
ios/RCCNavigationController.m 查看文件

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

+ 0
- 1
ios/RCCTabBarController.h 查看文件

@@ -5,7 +5,6 @@
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
 @property (nonatomic) BOOL tabBarHidden;
11 10
 

+ 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 查看文件

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