Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -26,7 +24,7 @@ public BottomTabs(Context context) {
setForceTint(true);
setId(ViewUtils.generateViewId());
createVisibilityAnimator();
setStyle(AppStyle.appStyle);
setStyle();
setFontFamily();
}

Expand All @@ -40,13 +38,20 @@ public void addTabs(List<ScreenParams> 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);
}
Expand Down Expand Up @@ -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() {
Expand Down
34 changes: 17 additions & 17 deletions ios/RCCNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
Expand Down
1 change: 0 additions & 1 deletion ios/RCCTabBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions ios/RCCTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
92 changes: 4 additions & 88 deletions ios/RCCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down