fix(tabs): dynamic styling fixes - iconSource

selectedItemColor and unSelectedItemColor
This commit is contained in:
Vasko
2020-03-31 11:33:46 +03:00
parent 511415fb1f
commit 32a55d35ae
6 changed files with 68 additions and 11 deletions

View File

@@ -752,18 +752,19 @@ export class BottomNavigation extends TabNavigationBase {
this.setItemsColors(this.tabStrip.items);
}
public setTabBarItemTitle(tabStripItem: TabStripItem, value: string): void {
private updateItem(tabStripItem: TabStripItem): void {
// TODO: Should figure out a way to do it directly with the the nativeView
const tabStripItemIndex = this.tabStrip.items.indexOf(tabStripItem);
const tabItemSpec = this.createTabItemSpec(tabStripItem);
this.updateAndroidItemAt(tabStripItemIndex, tabItemSpec);
}
public setTabBarItemTitle(tabStripItem: TabStripItem, value: string): void {
this.updateItem(tabStripItem);
}
public setTabBarItemBackgroundColor(tabStripItem: TabStripItem, value: android.graphics.drawable.Drawable | Color): void {
// TODO: Should figure out a way to do it directly with the the nativeView
const tabStripItemIndex = this.tabStrip.items.indexOf(tabStripItem);
const tabItemSpec = this.createTabItemSpec(tabStripItem);
this.updateAndroidItemAt(tabStripItemIndex, tabItemSpec);
this.updateItem(tabStripItem);
}
public _setItemColor(tabStripItem: TabStripItem) {
@@ -813,6 +814,10 @@ export class BottomNavigation extends TabNavigationBase {
this.setIconColor(tabStripItem);
}
public setTabBarIconSource(tabStripItem: TabStripItem, value: number | Color): void {
this.updateItem(tabStripItem);
}
public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: Font): void {
if (value.fontSize) {
tabStripItem.nativeViewProtected.setTextSize(value.fontSize);

View File

@@ -377,6 +377,15 @@ export class BottomNavigation extends TabNavigationBase {
this.setViewAttributes(tabStripItem.nativeView, tabStripItem.label);
}
private setItemColors(): void {
if (this._selectedItemColor) {
this.viewController.tabBar.selectedImageTintColor = this._selectedItemColor.ios;
}
if (this._unSelectedItemColor) {
this.viewController.tabBar.unselectedItemTintColor = this._unSelectedItemColor.ios;
}
}
public setTabBarIconColor(tabStripItem: TabStripItem, value: UIColor | Color): void {
if (!this._unSelectedItemColor && !this._selectedItemColor) {
const image = this.getIcon(tabStripItem);
@@ -386,6 +395,10 @@ export class BottomNavigation extends TabNavigationBase {
}
}
public setTabBarIconSource(tabStripItem: TabStripItem, value: UIColor | Color): void {
this.updateItem(tabStripItem);
}
public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: Font): void {
this.setViewAttributes(tabStripItem.nativeView, tabStripItem.label);
}
@@ -410,6 +423,7 @@ export class BottomNavigation extends TabNavigationBase {
public setTabBarSelectedItemColor(value: Color) {
this._selectedItemColor = value;
this.setItemColors();
}
public getTabBarUnSelectedItemColor(): Color {
@@ -418,6 +432,7 @@ export class BottomNavigation extends TabNavigationBase {
public setTabBarUnSelectedItemColor(value: Color) {
this._unSelectedItemColor = value;
this.setItemColors();
}
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
@@ -577,6 +592,17 @@ export class BottomNavigation extends TabNavigationBase {
}
}
private updateItem(tabStripItem: TabStripItem): void {
const tabBarItem = this.createTabBarItem(tabStripItem, tabStripItem._index);
const tabBarItemController = this._ios.viewControllers[tabStripItem._index];
updateTitleAndIconPositions(tabStripItem, tabBarItem, tabBarItemController);
this.setViewAttributes(tabBarItem, tabStripItem.label);
tabBarItemController.tabBarItem = tabBarItem;
tabStripItem.setNativeView(tabBarItem);
}
private createTabBarItem(item: TabStripItem, index: number): UITabBarItem {
let image: UIImage;
let title: string;