diff --git a/android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java b/android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java index 1a3e38af71e..6c7be214981 100644 --- a/android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java +++ b/android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java @@ -229,8 +229,6 @@ public void updateScreenStyle(String screenInstanceId, Bundle styleParams) { for (int i = 0; i < bottomTabs.getItemsCount(); i++) { screenStacks[i].updateScreenStyle(screenInstanceId, styleParams); } - - bottomTabs.updateTabStyle(styleParams); } @Override diff --git a/android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java b/android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java index 27eb6a97cf9..c4a1eab69c7 100644 --- a/android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java +++ b/android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java @@ -126,14 +126,6 @@ private StyleParams createDefaultStyleParams() { result.titleBarButtonFontFamily = new StyleParams.Font(); result.titleBarHeight = -1; result.screenAnimationType = "slide-up"; - - result.bottomTabsColor = getDefaultBottomTabsColor(); - result.bottomTabsButtonColor = getDefaultBottomTabsButtonColor(); - result.selectedBottomTabsButtonColor = getDefaultSelectedBottomTabsButtonColor(); - - result.bottomTabBadgeTextColor = getBottomTabBadgeTextColor(); - result.bottomTabBadgeBackgroundColor = getBottomTabBadgeBackgroundColor(); - return result; } diff --git a/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java b/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java index a0e28d54de7..7ca224e6edc 100644 --- a/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java +++ b/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java @@ -2,7 +2,6 @@ import android.content.Context; import android.graphics.Color; -import android.os.Bundle; import android.text.TextUtils; import com.aurelhubert.ahbottomnavigation.AHBottomNavigation; @@ -11,7 +10,6 @@ import com.reactnativenavigation.params.AppStyle; import com.reactnativenavigation.params.ScreenParams; import com.reactnativenavigation.params.StyleParams; -import com.reactnativenavigation.params.parsers.StyleParamsParser; import com.reactnativenavigation.utils.ViewUtils; import com.reactnativenavigation.views.utils.Constants; @@ -26,7 +24,7 @@ public BottomTabs(Context context) { setForceTint(true); setId(ViewUtils.generateViewId()); createVisibilityAnimator(); - setStyle(AppStyle.appStyle); + setStyle(); setFontFamily(); } @@ -40,13 +38,20 @@ public void addTabs(List params, OnTabSelectedListener onTabSelect setTitlesDisplayState(); } - public void updateTabStyle(Bundle styleParams) { - StyleParams parsedStyleParams = new StyleParamsParser(styleParams).parse(); - this.setStyleFromScreen(parsedStyleParams); - } - public void setStyleFromScreen(StyleParams params) { - this.setStyle(params); + if (params.bottomTabsColor.hasColor()) { + setBackgroundColor(params.bottomTabsColor); + } + if (params.bottomTabsButtonColor.hasColor()) { + if (getInactiveColor() != params.bottomTabsButtonColor.getColor()) { + setInactiveColor(params.bottomTabsButtonColor.getColor()); + } + } + if (params.selectedBottomTabsButtonColor.hasColor()) { + if (getAccentColor() != params.selectedBottomTabsButtonColor.getColor()) { + setAccentColor(params.selectedBottomTabsButtonColor.getColor()); + } + } setVisibility(params.bottomTabsHidden, true); } @@ -127,27 +132,23 @@ private void createVisibilityAnimator() { Constants.BOTTOM_TABS_HEIGHT); } - private void setStyle(StyleParams params) { - if (params.bottomTabBadgeBackgroundColor.hasColor()) { + private void setStyle() { + if (hasBadgeBackgroundColor()) { setNotificationBackgroundColor(AppStyle.appStyle.bottomTabBadgeBackgroundColor.getColor()); } - if (params.bottomTabBadgeTextColor.hasColor()) { + if (hasBadgeTextColor()) { setNotificationTextColor(AppStyle.appStyle.bottomTabBadgeTextColor.getColor()); } + } - if (params.bottomTabsColor.hasColor()) { - setBackgroundColor(params.bottomTabsColor); - } - if (params.bottomTabsButtonColor.hasColor()) { - if (getInactiveColor() != params.bottomTabsButtonColor.getColor()) { - setInactiveColor(params.bottomTabsButtonColor.getColor()); - } - } - if (params.selectedBottomTabsButtonColor.hasColor()) { - if (getAccentColor() != params.selectedBottomTabsButtonColor.getColor()) { - setAccentColor(params.selectedBottomTabsButtonColor.getColor()); - } - } + private boolean hasBadgeTextColor() { + return AppStyle.appStyle.bottomTabBadgeTextColor != null && + AppStyle.appStyle.bottomTabBadgeTextColor.hasColor(); + } + + private boolean hasBadgeBackgroundColor() { + return AppStyle.appStyle.bottomTabBadgeBackgroundColor != null && + AppStyle.appStyle.bottomTabBadgeBackgroundColor.hasColor(); } private void setFontFamily() { diff --git a/ios/RCCNavigationController.m b/ios/RCCNavigationController.m index 130ed6df59e..bbf0e534559 100755 --- a/ios/RCCNavigationController.m +++ b/ios/RCCNavigationController.m @@ -337,23 +337,23 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio // setStyle if ([performAction isEqualToString:@"setStyle"]) { - for (UIViewController *viewController in self.viewControllers) { - if ([viewController isKindOfClass:[RCCViewController class]]) - { - RCCViewController *rccViewController = (RCCViewController*)viewController; - - NSDictionary *navigatorStyle = [[NSDictionary alloc] initWithDictionary:actionParams copyItems:YES]; - NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:rccViewController.navigatorStyle]; - - // there are a few styles that we don't want to remember from our parent (they should be local) - [mergedStyle setValuesForKeysWithDictionary:navigatorStyle]; - navigatorStyle = mergedStyle; - - rccViewController.navigatorStyle = navigatorStyle; - - [rccViewController setStyleOnInit]; - [rccViewController updateStyle]; - } + + NSDictionary *navigatorStyle = actionParams; + + // merge the navigatorStyle of our parent + if ([self.topViewController isKindOfClass:[RCCViewController class]]) + { + RCCViewController *parent = (RCCViewController*)self.topViewController; + NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:parent.navigatorStyle]; + + // there are a few styles that we don't want to remember from our parent (they should be local) + [mergedStyle setValuesForKeysWithDictionary:navigatorStyle]; + navigatorStyle = mergedStyle; + + parent.navigatorStyle = navigatorStyle; + + [parent setStyleOnInit]; + [parent updateStyle]; } } } diff --git a/ios/RCCTabBarController.h b/ios/RCCTabBarController.h index c9d69fc6c0a..e27c6a44cbc 100755 --- a/ios/RCCTabBarController.h +++ b/ios/RCCTabBarController.h @@ -5,6 +5,5 @@ - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge; - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge completion:(void (^)(void))completion; -+ (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1; @end diff --git a/ios/RCCTabBarController.m b/ios/RCCTabBarController.m index eb27937974d..179c684c7ef 100755 --- a/ios/RCCTabBarController.m +++ b/ios/RCCTabBarController.m @@ -55,7 +55,7 @@ - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectView return YES; } -+ (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1 +- (UIImage *)image:(UIImage*)image withColor:(UIColor *)color1 { UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale); CGContextRef context = UIGraphicsGetCurrentContext(); @@ -159,7 +159,7 @@ - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children iconImage = [RCTConvert UIImage:icon]; if (buttonColor) { - iconImage = [[RCCTabBarController image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; + iconImage = [[self image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; } } UIImage *iconImageSelected = nil; @@ -327,7 +327,7 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio if (icon && icon != (id)[NSNull null]) { iconImage = [RCTConvert UIImage:icon]; - iconImage = [[RCCTabBarController image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; + iconImage = [[self image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; viewController.tabBarItem.image = iconImage; } diff --git a/ios/RCCViewController.m b/ios/RCCViewController.m index 83ac039b5c1..964e8a9d0f6 100755 --- a/ios/RCCViewController.m +++ b/ios/RCCViewController.m @@ -484,95 +484,11 @@ -(void)setStyleOnAppearForViewController:(UIViewController*)viewController appea [viewController setNeedsStatusBarAppearanceUpdate]; } - if (viewController.tabBarController && viewController.tabBarController.tabBar != (id)[NSNull null]) { + NSNumber *tabBarHidden = self.navigatorStyle[@"tabBarHidden"]; + BOOL tabBarHiddenBool = tabBarHidden ? [tabBarHidden boolValue] : NO; + if (tabBarHiddenBool) { UITabBar *tabBar = viewController.tabBarController.tabBar; - - if (tabBar && tabBar != (id)[NSNull null]) { - UIColor *buttonColor = nil; - UIColor *selectedButtonColor = nil; - UIColor *labelColor = nil; - UIColor *selectedLabelColor = nil; - - NSNumber *tabBarHidden = self.navigatorStyle[@"tabBarHidden"]; - BOOL tabBarHiddenBool = tabBarHidden ? [tabBarHidden boolValue] : NO; - if (tabBarHiddenBool) { - tabBar.transform = CGAffineTransformMakeTranslation(0, tabBar.frame.size.height); - } - - NSString *tabBarButtonColor = self.navigatorStyle[@"tabBarButtonColor"]; - NSString *tabBarSelectedButtonColor = self.navigatorStyle[@"tabBarSelectedButtonColor"]; - - if (tabBarButtonColor) - { - buttonColor = tabBarButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarButtonColor] : nil; - - if (tabBarSelectedButtonColor) { - selectedButtonColor = tabBarSelectedButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedButtonColor] : nil; - - tabBar.tintColor = selectedLabelColor = selectedButtonColor; - tabBar.unselectedItemTintColor = labelColor = buttonColor; - } - else { - tabBar.tintColor = labelColor = buttonColor; - } - } - else if (tabBarSelectedButtonColor) { - selectedButtonColor = tabBarSelectedButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedButtonColor] : nil; - tabBar.tintColor = selectedLabelColor = selectedButtonColor; - } - - NSString *tabBarLabelColor = self.navigatorStyle[@"tabBarLabelColor"]; - if(tabBarLabelColor) { - UIColor *color = tabBarLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarLabelColor] : nil; - labelColor = color; - } - NSString *tabBarSelectedLabelColor = self.navigatorStyle[@"tabBarSelectedLabelColor"]; - if(tabBarLabelColor) { - UIColor *color = tabBarSelectedLabelColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarSelectedLabelColor] : nil; - selectedLabelColor = color; - } - - NSString *tabBarBackgroundColor = self.navigatorStyle[@"tabBarBackgroundColor"]; - if (tabBarBackgroundColor) - { - UIColor *color = tabBarBackgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:tabBarBackgroundColor] : nil; - tabBar.barTintColor = color; - } - - NSNumber *tabBarTranslucent = self.navigatorStyle[@"tabBarTranslucent"]; - if (tabBarTranslucent) - { - BOOL tabBarTranslucentBool = tabBarTranslucent ? [tabBarTranslucent boolValue] : NO; - tabBar.translucent = tabBarTranslucentBool; - } - - NSNumber *tabBarHideShadow = self.navigatorStyle[@"tabBarHideShadow"]; - if (tabBarHideShadow) - { - BOOL tabBarHideShadowBool = tabBarHideShadow ? [tabBarHideShadow boolValue] : NO; - tabBar.clipsToBounds = tabBarHideShadowBool ? YES : NO; - } - - for (UIViewController *tabViewController in [viewController.tabBarController viewControllers]) { - NSMutableDictionary *unselectedAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"tabBarText" baseFont:[UIFont systemFontOfSize:10]]; - if (!unselectedAttributes[NSForegroundColorAttributeName] && labelColor) { - unselectedAttributes[NSForegroundColorAttributeName] = labelColor; - } - [tabViewController.tabBarItem setTitleTextAttributes:unselectedAttributes forState:UIControlStateNormal]; - - - NSMutableDictionary *selectedAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"tabBarSelectedText" baseFont:[UIFont systemFontOfSize:10]]; - if (!selectedAttributes[NSForegroundColorAttributeName] && selectedLabelColor) { - selectedAttributes[NSForegroundColorAttributeName] = selectedLabelColor; - } - [tabViewController.tabBarItem setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected]; - - if (buttonColor) - { - tabViewController.tabBarItem.image = [[RCCTabBarController image:tabViewController.tabBarItem.image withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; - } - } - } + tabBar.transform = CGAffineTransformMakeTranslation(0, tabBar.frame.size.height); } NSNumber *navBarHidden = self.navigatorStyle[@"navBarHidden"];