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..7ca224e6edc 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(); + } } } @@ -76,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; } diff --git a/docs/screen-api.md b/docs/screen-api.md index 52871761e7e..47645e9fea9 100644 --- a/docs/screen-api.md +++ b/docs/screen-api.md @@ -242,6 +242,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) }); ``` 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 6531ae52518..3affba63284 100644 --- a/src/deprecated/platformSpecificDeprecated.ios.js +++ b/src/deprecated/platformSpecificDeprecated.ios.js @@ -441,14 +441,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, }); } }