From 076ee7311e27554eb019440dc68cf673ce7e2184 Mon Sep 17 00:00:00 2001 From: Daniel Lang Date: Mon, 4 Dec 2017 12:55:16 +0100 Subject: [PATCH 01/12] setStyle to style the according TabBar (#2224) setTabButton -> has now the property 'label' to change the label of the TabButton iOS update style-update rutine to update each viewcontroller in a NavigationViewController tabButtonColor improvement --- .../layouts/BottomTabsLayout.java | 2 + .../params/parsers/StyleParamsParser.java | 8 ++ .../views/BottomTabs.java | 51 +++++----- ios/RCCNavigationController.m | 34 +++---- ios/RCCTabBarController.h | 1 + ios/RCCTabBarController.m | 6 +- ios/RCCViewController.m | 92 ++++++++++++++++++- 7 files changed, 144 insertions(+), 50 deletions(-) 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 6c7be214981..1a3e38af71e 100644 --- a/android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java +++ b/android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java @@ -229,6 +229,8 @@ 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 c4a1eab69c7..27eb6a97cf9 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,6 +126,14 @@ 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 7ca224e6edc..a0e28d54de7 100644 --- a/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java +++ b/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java @@ -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; @@ -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; @@ -24,7 +26,7 @@ public BottomTabs(Context context) { setForceTint(true); setId(ViewUtils.generateViewId()); createVisibilityAnimator(); - setStyle(); + setStyle(AppStyle.appStyle); setFontFamily(); } @@ -38,20 +40,13 @@ 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) { - 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); } @@ -132,23 +127,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() { diff --git a/ios/RCCNavigationController.m b/ios/RCCNavigationController.m index bbf0e534559..130ed6df59e 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"]) { - - 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]; + navigatorStyle = mergedStyle; + + rccViewController.navigatorStyle = navigatorStyle; + + [rccViewController setStyleOnInit]; + [rccViewController updateStyle]; + } } } } diff --git a/ios/RCCTabBarController.h b/ios/RCCTabBarController.h index e27c6a44cbc..c9d69fc6c0a 100755 --- a/ios/RCCTabBarController.h +++ b/ios/RCCTabBarController.h @@ -5,5 +5,6 @@ - (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 179c684c7ef..eb27937974d 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 = [[self image:iconImage withColor:buttonColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; + iconImage = [[RCCTabBarController 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 = [[self image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; + iconImage = [[RCCTabBarController image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; viewController.tabBarItem.image = iconImage; } diff --git a/ios/RCCViewController.m b/ios/RCCViewController.m index 964e8a9d0f6..83ac039b5c1 100755 --- a/ios/RCCViewController.m +++ b/ios/RCCViewController.m @@ -484,11 +484,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"]; From 2c9ba1d385974359fe171299db78e47cb3ed56f6 Mon Sep 17 00:00:00 2001 From: Guy Carmeli Date: Tue, 5 Dec 2017 08:13:34 +0200 Subject: [PATCH 02/12] Revert "setStyle to style the according TabBar (#2224)" (#2276) This reverts commit 076ee7311e27554eb019440dc68cf673ce7e2184. --- .../layouts/BottomTabsLayout.java | 2 - .../params/parsers/StyleParamsParser.java | 8 -- .../views/BottomTabs.java | 51 +++++----- ios/RCCNavigationController.m | 34 +++---- ios/RCCTabBarController.h | 1 - ios/RCCTabBarController.m | 6 +- ios/RCCViewController.m | 92 +------------------ 7 files changed, 50 insertions(+), 144 deletions(-) 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"]; From 7b429da6c68b43a6dbdb8d2a672e572b77238cd5 Mon Sep 17 00:00:00 2001 From: Yedidya Kennard Date: Sun, 10 Dec 2017 10:37:27 +0000 Subject: [PATCH 03/12] Add a toString implementation to StyleParams Color (#2313) --- .../java/com/reactnativenavigation/params/StyleParams.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java b/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java index 24337a173c7..a09b25af0ed 100644 --- a/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java +++ b/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java @@ -48,6 +48,11 @@ public String getHexColor() { public int getColor(int defaultColor) { return hasColor() ? getColor() : defaultColor; } + + @Override + public String toString() { + return this.getHexColor(); + } } public static class Font { From 6a78a3282d05c86184da9596fbb0e402bf882200 Mon Sep 17 00:00:00 2001 From: Guy Carmeli Date: Sun, 10 Dec 2017 16:18:59 +0200 Subject: [PATCH 04/12] Find textual buttons in TitleBar by text instead of content description --- .../java/com/reactnativenavigation/views/TitleBarButton.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java b/android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java index 3487a915647..61384948e39 100644 --- a/android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java +++ b/android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java @@ -114,7 +114,7 @@ private void setFont() { @NonNull private ArrayList findActualTextViewInMenuByLabel() { ArrayList outViews = new ArrayList<>(); - parent.findViewsWithText(outViews, buttonParams.label, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); + parent.findViewsWithText(outViews, buttonParams.label, View.FIND_VIEWS_WITH_TEXT); return outViews; } From 57d016d83504b5edd27e3b0166186f4821bcbaa6 Mon Sep 17 00:00:00 2001 From: Guy Carmeli Date: Mon, 11 Dec 2017 11:21:33 +0200 Subject: [PATCH 05/12] Add commandType param to props which indicates if a screen is displayed using push or modal --- src/deprecated/platformSpecificDeprecated.android.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/deprecated/platformSpecificDeprecated.android.js b/src/deprecated/platformSpecificDeprecated.android.js index f1f5818c8d7..4e61ce86de9 100644 --- a/src/deprecated/platformSpecificDeprecated.android.js +++ b/src/deprecated/platformSpecificDeprecated.android.js @@ -80,6 +80,12 @@ function navigatorPush(navigator, params) { adapted = adaptNavigationParams(adapted); adapted.overrideBackPress = params.overrideBackPress; adapted.timestamp = Date.now(); + if (!adapted.passProps) { + adapted.passProps = {}; + } + if (!adapted.passProps.commandType) { + adapted.passProps.commandType = 'Push'; + } return newPlatformSpecific.push(adapted); } @@ -472,6 +478,12 @@ function showModal(params) { adapted = adaptNavigationParams(adapted); adapted.overrideBackPress = params.overrideBackPress; adapted.timestamp = Date.now(); + if (!adapted.passProps) { + adapted.passProps = {}; + } + if (!adapted.passProps.commandType) { + adapted.passProps.commandType = 'ShowModal'; + } newPlatformSpecific.showModal(adapted); } From 5398b9cc2a472be1222f3259733148c4685144ff Mon Sep 17 00:00:00 2001 From: Rafael Cerrejon Date: Mon, 11 Dec 2017 13:40:13 +0100 Subject: [PATCH 06/12] Missed comma (#2305) Missed Comma throw "unexpected Token" error. --- docs/top-level-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/top-level-api.md b/docs/top-level-api.md index e7792fe8fc3..863f452a360 100644 --- a/docs/top-level-api.md +++ b/docs/top-level-api.md @@ -75,7 +75,7 @@ Navigation.startTabBasedApp({      drawerShadow: true, // optional, add this if you want a side menu drawer shadow      contentOverlayColor: 'rgba(0,0,0,0.25)', // optional, add this if you want a overlay color when drawer is open leftDrawerWidth: 50, // optional, add this if you want a define left drawer width (50=percent) - rightDrawerWidth: 50 // optional, add this if you want a define right drawer width (50=percent) + rightDrawerWidth: 50, // optional, add this if you want a define right drawer width (50=percent) shouldStretchDrawer: true // optional, iOS only with 'MMDrawer' type, whether or not the panning gesture will “hard-stop” at the maximum width for a given drawer side, default : true }, type: 'MMDrawer', // optional, iOS only, types: 'TheSideBar', 'MMDrawer' default: 'MMDrawer' From ff3c6a8415476ffe8bcc134dce10576912133a4b Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 11 Dec 2017 19:05:14 +0530 Subject: [PATCH 07/12] Fix NPE when activity is relaunched on changing font size of the phone (#2319) --- .../reactnativenavigation/controllers/NavigationActivity.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java b/android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java index c646ad75268..341e6eca27a 100644 --- a/android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java +++ b/android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java @@ -63,7 +63,9 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (!NavigationApplication.instance.getReactGateway().hasStartedCreatingContext()) { + if (!NavigationApplication.instance.getReactGateway().hasStartedCreatingContext() || + getIntent() == null || + getIntent().getBundleExtra("ACTIVITY_PARAMS_BUNDLE") == null) { SplashActivity.start(this); finish(); return; From 8a2946f33f8e43a4a723c6cb72e58568592cde67 Mon Sep 17 00:00:00 2001 From: Marcus Andersson Date: Tue, 12 Dec 2017 18:19:12 +0100 Subject: [PATCH 08/12] [Android] Support for transparent statusbar with current screen rendered behind it (#2274) * add support to tell screen to place its self underneath the statusbar for android. * added property to documentation. --- .../controllers/Modal.java | 7 +++++++ .../params/StyleParams.java | 1 + .../params/parsers/StyleParamsParser.java | 5 +++++ .../reactnativenavigation/screens/Screen.java | 6 ++++++ .../reactnativenavigation/utils/StatusBar.java | 17 +++++++++++++++++ docs/styling-the-navigator.md | 1 + .../platformSpecificDeprecated.android.js | 1 + 7 files changed, 38 insertions(+) diff --git a/android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java b/android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java index 5e0949c5e1f..4ff1f95f8ed 100644 --- a/android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java +++ b/android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java @@ -120,6 +120,7 @@ interface OnModalDismissedListener { setAnimation(screenParams); setStatusBarStyle(screenParams.styleParams); setNavigationBarStyle(screenParams.styleParams); + setDrawUnderStatusBar(screenParams.styleParams); } private void setStatusBarStyle(StyleParams styleParams) { @@ -128,6 +129,12 @@ private void setStatusBarStyle(StyleParams styleParams) { StatusBar.setTextColorScheme(window.getDecorView(), styleParams.statusBarTextColorScheme); } + private void setDrawUnderStatusBar(StyleParams styleParams) { + Window window = getWindow(); + if (window == null) return; + StatusBar.displayOverScreen(window.getDecorView(), styleParams.drawUnderStatusBar); + } + private void setNavigationBarStyle(StyleParams styleParams) { NavigationBar.setColor(getWindow(), styleParams.navigationBarColor); } diff --git a/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java b/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java index a09b25af0ed..3c14938a614 100644 --- a/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java +++ b/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java @@ -89,6 +89,7 @@ public String toString() { public StatusBarTextColorScheme statusBarTextColorScheme; public Color statusBarColor; public boolean statusBarHidden; + public boolean drawUnderStatusBar; public Color contextualMenuStatusBarColor; public Color contextualMenuButtonsColor; public Color contextualMenuBackgroundColor; 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 c4a1eab69c7..b35876e98be 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 @@ -32,6 +32,7 @@ public StyleParams parse() { result.statusBarColor = getColor("statusBarColor", getDefaultStatusBarColor()); result.statusBarHidden = getBoolean("statusBarHidden", getDefaultStatusHidden()); result.statusBarTextColorScheme = StatusBarTextColorScheme.fromString(params.getString("statusBarTextColorScheme"), getDefaultStatusBarTextColorScheme()); + result.drawUnderStatusBar = params.getBoolean("drawUnderStatusBar", getDefaultDrawUnderStatusBar()); result.contextualMenuStatusBarColor = getColor("contextualMenuStatusBarColor", getDefaultContextualMenuStatusBarColor()); result.contextualMenuButtonsColor = getColor("contextualMenuButtonsColor", getDefaultContextualMenuButtonsColor()); result.contextualMenuBackgroundColor = getColor("contextualMenuBackgroundColor", getDefaultContextualMenuBackgroundColor()); @@ -281,6 +282,10 @@ private boolean getDefaultStatusHidden() { return AppStyle.appStyle != null && AppStyle.appStyle.statusBarHidden; } + private boolean getDefaultDrawUnderStatusBar() { + return AppStyle.appStyle != null && AppStyle.appStyle.drawUnderStatusBar; + } + private StyleParams.Font getDefaultBottomTabsFontFamily() { return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.bottomTabFontFamily; } diff --git a/android/app/src/main/java/com/reactnativenavigation/screens/Screen.java b/android/app/src/main/java/com/reactnativenavigation/screens/Screen.java index 0f8b67882fa..010212e6ad6 100644 --- a/android/app/src/main/java/com/reactnativenavigation/screens/Screen.java +++ b/android/app/src/main/java/com/reactnativenavigation/screens/Screen.java @@ -62,6 +62,7 @@ public Screen(AppCompatActivity activity, ScreenParams screenParams, LeftButtonO createViews(); EventBus.instance.register(this); sharedElements = new SharedElements(); + setDrawUnderStatusBar(styleParams.drawUnderStatusBar); } public void registerSharedElement(SharedElementTransition toView, String key) { @@ -106,6 +107,7 @@ public void setStyle() { setStatusBarHidden(styleParams.statusBarHidden); setStatusBarTextColorScheme(styleParams.statusBarTextColorScheme); setNavigationBarColor(styleParams.navigationBarColor); + setDrawUnderStatusBar(styleParams.drawUnderStatusBar); topBar.setStyle(styleParams); if (styleParams.screenBackgroundColor.hasColor()) { setBackgroundColor(styleParams.screenBackgroundColor.getColor()); @@ -174,6 +176,10 @@ private void setStatusBarHidden(boolean statusBarHidden) { StatusBar.setHidden(((NavigationActivity) activity).getScreenWindow(), statusBarHidden); } + private void setDrawUnderStatusBar(boolean drawUnderStatusBar) { + StatusBar.displayOverScreen(this, drawUnderStatusBar); + } + private void setStatusBarTextColorScheme(StatusBarTextColorScheme textColorScheme) { StatusBar.setTextColorScheme(this, textColorScheme); } diff --git a/android/app/src/main/java/com/reactnativenavigation/utils/StatusBar.java b/android/app/src/main/java/com/reactnativenavigation/utils/StatusBar.java index d5f3f07096b..af907d44bf4 100644 --- a/android/app/src/main/java/com/reactnativenavigation/utils/StatusBar.java +++ b/android/app/src/main/java/com/reactnativenavigation/utils/StatusBar.java @@ -30,6 +30,23 @@ public static void setColor(Window window, StyleParams.Color statusBarColor) { } } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static void displayOverScreen(View view, boolean shouldDisplay) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; + + if(shouldDisplay) { + int flags = view.getSystemUiVisibility(); + flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; + flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + view.setSystemUiVisibility(flags); + } else { + int flags = view.getSystemUiVisibility(); + flags &= ~View.SYSTEM_UI_FLAG_LAYOUT_STABLE; + flags &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + view.setSystemUiVisibility(flags); + } + } + @TargetApi(Build.VERSION_CODES.M) public static void setTextColorScheme(View view, StatusBarTextColorScheme textColorScheme) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; diff --git a/docs/styling-the-navigator.md b/docs/styling-the-navigator.md index e2b5b7cfbba..9888ac1defa 100644 --- a/docs/styling-the-navigator.md +++ b/docs/styling-the-navigator.md @@ -101,6 +101,7 @@ this.props.navigator.setStyle({ navBarButtonFontFamily: 'sans-serif-thin', // Change the font family of textual buttons topBarElevationShadowEnabled: false, // default: true. Disables TopBar elevation shadow on Lolipop and above statusBarColor: '#000000', // change the color of the status bar. + drawUnderStatusBar: false, // default: false, will draw the screen underneath the statusbar. Useful togheter with statusBarColor: transparent collapsingToolBarImage: "http://lorempixel.com/400/200/", // Collapsing Toolbar image. collapsingToolBarImage: require('../../img/topbar.jpg'), // Collapsing Toolbar image. Either use a url or require a local image. collapsingToolBarCollapsedColor: '#0f2362', // Collapsing Toolbar scrim color. diff --git a/src/deprecated/platformSpecificDeprecated.android.js b/src/deprecated/platformSpecificDeprecated.android.js index 4e61ce86de9..c17ef38a0cd 100644 --- a/src/deprecated/platformSpecificDeprecated.android.js +++ b/src/deprecated/platformSpecificDeprecated.android.js @@ -149,6 +149,7 @@ function convertStyleParams(originalStyleObject) { statusBarColor: processColor(originalStyleObject.statusBarColor), statusBarHidden: originalStyleObject.statusBarHidden, statusBarTextColorScheme: originalStyleObject.statusBarTextColorScheme, + drawUnderStatusBar: originalStyleObject.drawUnderStatusBar || false, topBarReactView: originalStyleObject.navBarCustomView, topBarReactViewAlignment: originalStyleObject.navBarComponentAlignment, topBarReactViewInitialProps: originalStyleObject.navBarCustomViewInitialProps, From 0ea0a7f5f6e001d7d3f7d64eb3f26673b800484c Mon Sep 17 00:00:00 2001 From: Chaitanya Bhagvan Date: Wed, 13 Dec 2017 15:27:20 +0530 Subject: [PATCH 09/12] Fix rn 0.50 repeated calls to onMeasure. (#2261) --- .../com/reactnativenavigation/views/ContentView.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/com/reactnativenavigation/views/ContentView.java b/android/app/src/main/java/com/reactnativenavigation/views/ContentView.java index 6d3c7b36e9e..978d7734a2a 100644 --- a/android/app/src/main/java/com/reactnativenavigation/views/ContentView.java +++ b/android/app/src/main/java/com/reactnativenavigation/views/ContentView.java @@ -66,9 +66,13 @@ public void unmountReactView() { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - int measuredHeight = viewMeasurer.getMeasuredHeight(heightMeasureSpec); - setMeasuredDimension(viewMeasurer.getMeasuredWidth(widthMeasureSpec), measuredHeight); + int widthSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST); + int heightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.AT_MOST); + + super.onMeasure(widthSpec, heightSpec); + + int measuredHeight = viewMeasurer.getMeasuredHeight(heightSpec); + setMeasuredDimension(viewMeasurer.getMeasuredWidth(widthSpec), measuredHeight); } @Override From 36ed3b0af5febbdd8b309f9311130acab81b2ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Birkir=20Rafn=20Gu=C3=B0j=C3=B3nsson?= Date: Wed, 13 Dec 2017 05:22:27 -0500 Subject: [PATCH 10/12] Add unregisterForPreviewingWithContext (#2239) * Preview API * Added preview actions and fail-guard wrappers * Remove old setters * Moved from passProps to actionParams * Move findNodeHandle to internal method * Removing findNodeHandle * Added height and option to dont 'pop' the view controller * Documentation update for peek and pop * Document how to access button press events * Commit by default in example. Because it's cool * Docs and if elses ifs then * Unregister previous ViewController on attempt to preview. * Merge conflict fail --- ios/RCCNavigationController.m | 4 +++- ios/RCCViewController.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ios/RCCNavigationController.m b/ios/RCCNavigationController.m index bbf0e534559..2714ad2e42b 100755 --- a/ios/RCCNavigationController.m +++ b/ios/RCCNavigationController.m @@ -172,6 +172,8 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio if ([self.topViewController isKindOfClass:[RCCViewController class]]) { RCCViewController *topViewController = ((RCCViewController*)self.topViewController); + topViewController.previewController = nil; + [topViewController.navigationController unregisterForPreviewingWithContext:topViewController.previewContext]; viewController.previewActions = previewActions; viewController.previewCommit = actionParams[@"previewCommit"] ? [actionParams[@"previewCommit"] boolValue] : YES; NSNumber *previewHeight = actionParams[@"previewHeight"]; @@ -184,7 +186,7 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio [bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { UIView *view = viewRegistry[previewViewID]; topViewController.previewView = view; - [topViewController registerForPreviewingWithDelegate:(id)topViewController sourceView:view]; + topViewController.previewContext = [topViewController registerForPreviewingWithDelegate:(id)topViewController sourceView:view]; }]; }); topViewController.previewController = viewController; diff --git a/ios/RCCViewController.h b/ios/RCCViewController.h index 27ca96d415a..5b35a755756 100755 --- a/ios/RCCViewController.h +++ b/ios/RCCViewController.h @@ -22,6 +22,7 @@ extern NSString* const RCCViewControllerCancelReactTouchesNotification; @property (nonatomic) UIView *previewView; @property (nonatomic) NSArray *previewActions; @property (nonatomic) BOOL previewCommit; +@property (nonatomic) id previewContext; + (UIViewController*)controllerWithLayout:(NSDictionary *)layout globalProps:(NSDictionary *)globalProps bridge:(RCTBridge *)bridge; From d17d26b7d7fc6e4f6a2f06477f5064e3258c51aa Mon Sep 17 00:00:00 2001 From: Eli Perkins Date: Wed, 13 Dec 2017 05:30:00 -0500 Subject: [PATCH 11/12] Ensure correct spelling of commandType (#2246) --- ios/RCCNavigationController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RCCNavigationController.m b/ios/RCCNavigationController.m index 2714ad2e42b..36602d27f21 100755 --- a/ios/RCCNavigationController.m +++ b/ios/RCCNavigationController.m @@ -259,7 +259,7 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio if (!component) return; NSMutableDictionary *passProps = [actionParams[@"passProps"] mutableCopy]; - passProps[@"commantType"] = @"resetTo"; + passProps[@"commandType"] = @"resetTo"; NSDictionary *navigatorStyle = actionParams[@"style"]; RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle globalProps:nil bridge:bridge]; From 119069777dcedad02756a6a605d6b3ecbc0de1f5 Mon Sep 17 00:00:00 2001 From: Krystof Celba Date: Thu, 14 Dec 2017 12:51:44 +0100 Subject: [PATCH 12/12] [Android] TopTabs font family (#2342) * Add topTabTextFontFamily style option * Add topTabTextFontFamily sample usage to example project --- .../params/StyleParams.java | 1 + .../params/parsers/StyleParamsParser.java | 6 +++++ .../reactnativenavigation/views/TopBar.java | 1 + .../reactnativenavigation/views/TopTabs.java | 22 +++++++++++++++++++ example/src/screens/types/TopTabs.js | 1 + .../platformSpecificDeprecated.android.js | 1 + 6 files changed, 32 insertions(+) diff --git a/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java b/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java index 3c14938a614..8a905b45f95 100644 --- a/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java +++ b/android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java @@ -125,6 +125,7 @@ public String toString() { public Font titleBarButtonFontFamily; public Color topTabTextColor; + public Font topTabTextFontFamily; public Color topTabIconColor; public Color selectedTopTabTextColor; public Color selectedTopTabIconColor; 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 b35876e98be..1e052ec171b 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 @@ -71,6 +71,7 @@ public StyleParams parse() { result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden()); result.topTabTextColor = getColor("topTabTextColor", getDefaultTopTabTextColor()); + result.topTabTextFontFamily = getFont("topTabTextFontFamily", getDefaultTopTabTextFontFamily()); result.topTabIconColor = getColor("topTabIconColor", getDefaultTopTabIconColor()); result.selectedTopTabIconColor = getColor("selectedTopTabIconColor", getDefaultSelectedTopTabIconColor()); result.selectedTopTabTextColor = getColor("selectedTopTabTextColor", getDefaultSelectedTopTabTextColor()); @@ -125,6 +126,7 @@ private StyleParams createDefaultStyleParams() { result.titleBarTitleFont = new StyleParams.Font(); result.titleBarSubtitleFontFamily = new StyleParams.Font(); result.titleBarButtonFontFamily = new StyleParams.Font(); + result.topTabTextFontFamily = new StyleParams.Font(); result.titleBarHeight = -1; result.screenAnimationType = "slide-up"; return result; @@ -306,6 +308,10 @@ private StyleParams.Font getDefaultSubtitleFontFamily() { return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.titleBarSubtitleFontFamily; } + private StyleParams.Font getDefaultTopTabTextFontFamily() { + return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.topTabTextFontFamily; + } + private StyleParams.Font getDefaultTitleBarButtonFont() { return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.titleBarButtonFontFamily; } diff --git a/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java b/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java index 22834bb8c95..dfda98caa99 100644 --- a/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java +++ b/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java @@ -213,6 +213,7 @@ private void setTopTabsStyle(StyleParams style) { topTabs.setTopTabsTextColor(style); topTabs.setSelectedTabIndicatorStyle(style); topTabs.setScrollable(style); + topTabs.setTopTabsTextFontFamily(style); } public void showContextualMenu(final ContextualMenuParams params, StyleParams styleParams, Callback onButtonClicked) { diff --git a/android/app/src/main/java/com/reactnativenavigation/views/TopTabs.java b/android/app/src/main/java/com/reactnativenavigation/views/TopTabs.java index 77d68d90a8d..456b2f9bcb4 100644 --- a/android/app/src/main/java/com/reactnativenavigation/views/TopTabs.java +++ b/android/app/src/main/java/com/reactnativenavigation/views/TopTabs.java @@ -2,7 +2,11 @@ import android.content.Context; import android.content.res.ColorStateList; +import android.graphics.Typeface; import android.support.design.widget.TabLayout; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; import com.reactnativenavigation.params.StyleParams; import com.reactnativenavigation.views.utils.TopTabsIconColorHelper; @@ -39,6 +43,24 @@ void setTopTabsTextColor(StyleParams style) { setTabTextColors(tabTextColor, selectedTabColor); } + void setTopTabsTextFontFamily(StyleParams style) { + if (style.topTabTextFontFamily.hasFont()) { + ViewGroup viewGroup = (ViewGroup) this.getChildAt(0); + + for (int tab = 0; tab < viewGroup.getChildCount(); tab++) { + ViewGroup tabViewGroup = (ViewGroup) viewGroup.getChildAt(tab); + + for (int i = 0; i < tabViewGroup.getChildCount(); i++) { + View tabViewChild = tabViewGroup.getChildAt(i); + if (tabViewChild instanceof TextView) { + ((TextView) tabViewChild).setTypeface( + style.topTabTextFontFamily.get(), Typeface.NORMAL); + } + } + } + } + } + void setScrollable(StyleParams style) { if (style.topTabsScrollable) { setTabMode(TabLayout.MODE_SCROLLABLE); diff --git a/example/src/screens/types/TopTabs.js b/example/src/screens/types/TopTabs.js index a8b06874b87..70454eca4c4 100644 --- a/example/src/screens/types/TopTabs.js +++ b/example/src/screens/types/TopTabs.js @@ -4,6 +4,7 @@ import {PixelRatio} from 'react-native'; class TopTabs extends React.Component { static navigatorStyle = { topTabTextColor: '#ffffff', + topTabTextFontFamily: 'BioRhyme-Bold', selectedTopTabTextColor: '#ff505c', // Icons diff --git a/src/deprecated/platformSpecificDeprecated.android.js b/src/deprecated/platformSpecificDeprecated.android.js index c17ef38a0cd..0ee116d489a 100644 --- a/src/deprecated/platformSpecificDeprecated.android.js +++ b/src/deprecated/platformSpecificDeprecated.android.js @@ -190,6 +190,7 @@ function convertStyleParams(originalStyleObject) { drawBelowTopBar: !originalStyleObject.drawUnderNavBar, topTabTextColor: processColor(originalStyleObject.topTabTextColor), + topTabTextFontFamily: originalStyleObject.topTabTextFontFamily, topTabIconColor: processColor(originalStyleObject.topTabIconColor), selectedTopTabIconColor: processColor(originalStyleObject.selectedTopTabIconColor), selectedTopTabTextColor: processColor(originalStyleObject.selectedTopTabTextColor),