From 531526fc6409790b44f5ea4be63fbe06d2c8c430 Mon Sep 17 00:00:00 2001 From: Daniel Lang Date: Thu, 23 Nov 2017 22:50:29 +0100 Subject: [PATCH 1/3] setTabButton -> has now the property 'label' to change the label of the TabButton --- .../views/BottomTabs.java | 18 +++++++++++++++--- ios/RCCTabBarController.m | 8 +++++++- .../platformSpecificDeprecated.ios.js | 6 ++++-- 3 files changed, 26 insertions(+), 6 deletions(-) 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 0f01e61a0b4..9f0d2fe7ef8 100644 --- a/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java +++ b/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java @@ -57,10 +57,22 @@ public void setStyleFromScreen(StyleParams params) { } public void setTabButton(ScreenParams params, Integer index) { - if (params.tabIcon != null) { + if (params.tabIcon != null || params.tabLabel != null) { AHBottomNavigationItem item = this.getItem(index); - item.setDrawable(params.tabIcon); - refresh(); + boolean tabNeedsRefresh = false; + + if (params.tabIcon != null) { + item.setDrawable(params.tabIcon); + tabNeedsRefresh = true; + } + if (params.tabLabel != null) { + item.setTitle(params.tabLabel); + tabNeedsRefresh = true; + } + + if (tabNeedsRefresh) { + this.refresh(); + } } } diff --git a/ios/RCCTabBarController.m b/ios/RCCTabBarController.m index d9f7955a287..179c684c7ef 100755 --- a/ios/RCCTabBarController.m +++ b/ios/RCCTabBarController.m @@ -329,8 +329,8 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio iconImage = [RCTConvert UIImage:icon]; iconImage = [[self image:iconImage withColor:self.tabBar.tintColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; viewController.tabBarItem.image = iconImage; - } + UIImage *iconImageSelected = nil; id selectedIcon = actionParams[@"selectedIcon"]; if (selectedIcon && selectedIcon != (id)[NSNull null]) @@ -338,6 +338,12 @@ - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actio iconImageSelected = [RCTConvert UIImage:selectedIcon]; viewController.tabBarItem.selectedImage = iconImageSelected; } + + id label = actionParams[@"label"]; + if (label && label != (id)[NSNull null]) + { + viewController.tabBarItem.title = label; + } } } diff --git a/src/deprecated/platformSpecificDeprecated.ios.js b/src/deprecated/platformSpecificDeprecated.ios.js index ff95dfb0717..0d05a129afd 100644 --- a/src/deprecated/platformSpecificDeprecated.ios.js +++ b/src/deprecated/platformSpecificDeprecated.ios.js @@ -420,14 +420,16 @@ function navigatorSetTabButton(navigator, params) { Controllers.TabBarControllerIOS(controllerID + '_tabs').setTabButton({ tabIndex: params.tabIndex, icon: params.icon, - selectedIcon: params.selectedIcon + selectedIcon: params.selectedIcon, + label: params.label, }); } else { Controllers.TabBarControllerIOS(controllerID + '_tabs').setTabButton({ contentId: navigator.navigatorID, contentType: 'NavigationControllerIOS', icon: params.icon, - selectedIcon: params.selectedIcon + selectedIcon: params.selectedIcon, + label: params.label, }); } } From 23ecde0ef49e3620361f6628d52289f9c45fe284 Mon Sep 17 00:00:00 2001 From: Daniel Lang Date: Thu, 23 Nov 2017 23:13:58 +0100 Subject: [PATCH 2/3] Add to documentation --- docs/screen-api.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/screen-api.md b/docs/screen-api.md index c015df0e746..ec2c5d5f886 100644 --- a/docs/screen-api.md +++ b/docs/screen-api.md @@ -232,6 +232,7 @@ this.props.navigator.setTabButton({ tabIndex: 0, // (optional) if missing, the icon will be added to this screen's tab icon: require('../img/one.png'), // local image asset for the tab icon unselected state (optional) selectedIcon: require('../img/one_selected.png'), // local image asset for the tab icon selected state (optional, iOS only) + label: 'New Label' // tab label that appears under the icon (optional) }); ``` From 3c6c6f230610642979f9bd2978eb1037f6b1bf12 Mon Sep 17 00:00:00 2001 From: Daniel Lang Date: Thu, 23 Nov 2017 23:23:01 +0100 Subject: [PATCH 3/3] [BugFix] use i instead of 0 to check all TabItems --- .../main/java/com/reactnativenavigation/views/BottomTabs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9f0d2fe7ef8..7ca224e6edc 100644 --- a/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java +++ b/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java @@ -88,7 +88,7 @@ private void setTitlesDisplayState() { private boolean hasTabsWithLabels() { for (int i = 0; i < getItemsCount(); i++) { - String title = getItem(0).getTitle(getContext()); + String title = getItem(i).getTitle(getContext()); if (!TextUtils.isEmpty(title)) { return true; }