mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Bottom nav color ios fix (#8384)
* fix(bottom-navigation): color in ios fix * chore: improving fix and added description * chore: typo fix * chore: updated comment * chore: condition check updated
This commit is contained in:
@ -377,7 +377,7 @@ export class BottomNavigation extends TabNavigationBase {
|
|||||||
|
|
||||||
public setTabBarItemColor(tabStripItem: TabStripItem, value: UIColor | Color): void {
|
public setTabBarItemColor(tabStripItem: TabStripItem, value: UIColor | Color): void {
|
||||||
const states = getTitleAttributesForStates(tabStripItem.label);
|
const states = getTitleAttributesForStates(tabStripItem.label);
|
||||||
applyStatesToItem(tabStripItem.nativeView, states);
|
applyStatesToItem(tabStripItem.nativeView, states, this.viewController.tabBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setTabBarIconColor(tabStripItem: TabStripItem, value: UIColor | Color): void {
|
public setTabBarIconColor(tabStripItem: TabStripItem, value: UIColor | Color): void {
|
||||||
@ -389,7 +389,7 @@ export class BottomNavigation extends TabNavigationBase {
|
|||||||
|
|
||||||
public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: Font): void {
|
public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: Font): void {
|
||||||
const states = getTitleAttributesForStates(tabStripItem.label);
|
const states = getTitleAttributesForStates(tabStripItem.label);
|
||||||
applyStatesToItem(tabStripItem.nativeView, states);
|
applyStatesToItem(tabStripItem.nativeView, states, this.viewController.tabBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setTabBarItemTextTransform(tabStripItem: TabStripItem, value: TextTransform): void {
|
public setTabBarItemTextTransform(tabStripItem: TabStripItem, value: TextTransform): void {
|
||||||
@ -519,7 +519,7 @@ export class BottomNavigation extends TabNavigationBase {
|
|||||||
updateTitleAndIconPositions(tabStripItem, tabBarItem, controller);
|
updateTitleAndIconPositions(tabStripItem, tabBarItem, controller);
|
||||||
|
|
||||||
const states = getTitleAttributesForStates(tabStripItem.label);
|
const states = getTitleAttributesForStates(tabStripItem.label);
|
||||||
applyStatesToItem(tabBarItem, states);
|
applyStatesToItem(tabBarItem, states, this.viewController.tabBar);
|
||||||
|
|
||||||
controller.tabBarItem = tabBarItem;
|
controller.tabBarItem = tabBarItem;
|
||||||
tabStripItem._index = i;
|
tabStripItem._index = i;
|
||||||
@ -719,11 +719,20 @@ function getTitleAttributesForStates(view: View): TabStates {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyStatesToItem(item: UITabBarItem, states: TabStates) {
|
function applyStatesToItem(item: UITabBarItem, states: TabStates, tabBar: UITabBar) {
|
||||||
if (!states) {
|
if (!states) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.setTitleTextAttributesForState(states.normalState, UIControlState.Normal);
|
item.setTitleTextAttributesForState(states.normalState, UIControlState.Normal);
|
||||||
item.setTitleTextAttributesForState(states.selectedState, UIControlState.Selected);
|
item.setTitleTextAttributesForState(states.selectedState, UIControlState.Selected);
|
||||||
|
|
||||||
|
// there's a bug when setting the item color on ios 13 if there's no background set to the tabstrip
|
||||||
|
// https://books.google.bg/books?id=99_BDwAAQBAJ&q=tabBar.unselectedItemTintColor
|
||||||
|
// to fix the above issue we are applying the selected fix only for the case, when there is no background set
|
||||||
|
// in that case we have the following known issue:
|
||||||
|
// we will set the color to all unselected items, so you won't be able to set different colors for the different not selected items
|
||||||
|
if (!tabBar.barTintColor && states.normalState[UITextAttributeTextColor] && (majorVersion > 9)) {
|
||||||
|
tabBar.unselectedItemTintColor = states.normalState[UITextAttributeTextColor];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user