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 @@ -16,6 +16,7 @@
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.WritableMap;
import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.events.Event;
import com.reactnativenavigation.events.EventBus;
import com.reactnativenavigation.events.ScreenChangedEvent;
import com.reactnativenavigation.params.ActivityParams;
Expand Down Expand Up @@ -229,6 +230,8 @@ public void updateScreenStyle(String screenInstanceId, Bundle styleParams) {
for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
screenStacks[i].updateScreenStyle(screenInstanceId, styleParams);
}

bottomTabs.setStyleFromScreen(this.getCurrentScreen().getStyleParams());
}

@Override
Expand Down Expand Up @@ -360,7 +363,7 @@ public void run(ScreenStack param) {

private boolean hasBackgroundColor(StyleParams params) {
return params.screenBackgroundColor != null &&
params.screenBackgroundColor.hasColor();
params.screenBackgroundColor.hasColor();
}

private void setStyleFromScreen(StyleParams params) {
Expand Down Expand Up @@ -391,7 +394,7 @@ public void pop(final ScreenParams params) {
performOnStack(params.getNavigatorId(), new Task<ScreenStack>() {
@Override
public void run(ScreenStack stack) {
stack.pop(params.animateScreenTransitions, params.timestamp, new ScreenStack.OnScreenPop() {
stack.pop(params.animateScreenTransitions, params.timestamp, new ScreenStack.OnScreenPop() {
@Override
public void onScreenPopAnimationEnd() {
setBottomTabsStyleFromCurrentScreen();
Expand Down Expand Up @@ -450,8 +453,8 @@ private void performOnStack(String navigatorId, Task<ScreenStack> task) {
task.run(screenStack);
} catch (ScreenStackNotFoundException e) {
Log.e("Navigation", "Could not perform action on stack [" + navigatorId + "]." +
"This should not have happened, it probably means a navigator action" +
"was called from an unmounted tab.");
"This should not have happened, it probably means a navigator action" +
"was called from an unmounted tab.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ private StyleParams createDefaultStyleParams() {
result.titleBarHeight = -1;
result.screenAnimationType = "slide-up";
result.drawUnderStatusBar = false;

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 @@ -216,7 +216,7 @@ public void setTopBarVisible(boolean visible, boolean animate) {
}

public void setTitleBarTitle(String title) {
topBar.setTitle(title, styleParams);
topBar.setTitle(title, styleParams);
}

public void setTitleBarSubtitle(String subtitle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;

import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
Expand All @@ -10,6 +11,7 @@
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 @@ -21,37 +23,25 @@ public class BottomTabs extends AHBottomNavigation {

public BottomTabs(Context context) {
super(context);

setForceTint(true);
setId(ViewUtils.generateViewId());
createVisibilityAnimator();
setStyle();
setStyle(AppStyle.appStyle);
setFontFamily();
}

public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
for (ScreenParams screenParams : params) {
AHBottomNavigationItem item = new AHBottomNavigationItem(screenParams.tabLabel, screenParams.tabIcon,
Color.GRAY);
AHBottomNavigationItem item = new AHBottomNavigationItem(screenParams.tabLabel, screenParams.tabIcon, Color.GRAY);
addItem(item);
setOnTabSelectedListener(onTabSelectedListener);
}
setTitlesDisplayState();
}

public void setStyleFromScreen(StyleParams 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());
}
}
this.setStyle(params);

setVisibility(params.bottomTabsHidden, true);
}
Expand Down Expand Up @@ -132,23 +122,27 @@ private void createVisibilityAnimator() {
Constants.BOTTOM_TABS_HEIGHT);
}

private void setStyle() {
if (hasBadgeBackgroundColor()) {
private void setStyle(StyleParams params) {
if (params.bottomTabBadgeBackgroundColor.hasColor()) {
setNotificationBackgroundColor(AppStyle.appStyle.bottomTabBadgeBackgroundColor.getColor());
}
if (hasBadgeTextColor()) {
if (params.bottomTabBadgeTextColor.hasColor()) {
setNotificationTextColor(AppStyle.appStyle.bottomTabBadgeTextColor.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();
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 void setFontFamily() {
Expand Down
36 changes: 19 additions & 17 deletions ios/RCCNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -339,23 +339,25 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio
// setStyle
if ([performAction isEqualToString:@"setStyle"])
{

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];
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];

rccViewController.navigatorStyle = mergedStyle;

[rccViewController setStyleOnInit];

if (viewController == self.topViewController) {
[rccViewController updateStyle];
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ios/RCCTabBarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

- (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;

@property (nonatomic) BOOL tabBarHidden;

Expand Down
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 = [[self image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
iconImage = [[RCCTabBarController 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 = [[self image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
iconImage = [[RCCTabBarController image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
viewController.tabBarItem.image = iconImage;
}

Expand Down
92 changes: 88 additions & 4 deletions ios/RCCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,95 @@ -(void)setStyleOnAppearForViewController:(UIViewController*)viewController appea
[viewController setNeedsStatusBarAppearanceUpdate];
}

NSNumber *tabBarHidden = self.navigatorStyle[@"tabBarHidden"];
BOOL tabBarHiddenBool = tabBarHidden ? [tabBarHidden boolValue] : NO;
if (tabBarHiddenBool) {
if (viewController.tabBarController && viewController.tabBarController.tabBar != (id)[NSNull null]) {
UITabBar *tabBar = viewController.tabBarController.tabBar;
tabBar.transform = CGAffineTransformMakeTranslation(0, tabBar.frame.size.height);

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];
}
}
}
}

NSNumber *navBarHidden = self.navigatorStyle[@"navBarHidden"];
Expand Down