Merge pull request #8315 from NativeScript/tab-styles-fixes

fix(android): Bugs in tab strip items when changing styles dynamically
This commit is contained in:
Alexander Vakrilov
2020-02-06 18:12:25 +02:00
committed by GitHub
3 changed files with 18 additions and 7 deletions

View File

@@ -614,6 +614,9 @@ export class BottomNavigation extends TabNavigationBase {
private getIcon(tabStripItem: TabStripItem): android.graphics.drawable.BitmapDrawable { private getIcon(tabStripItem: TabStripItem): android.graphics.drawable.BitmapDrawable {
const iconSource = tabStripItem.image && tabStripItem.image.src; const iconSource = tabStripItem.image && tabStripItem.image.src;
if (!iconSource) {
return null;
}
let is: ImageSource; let is: ImageSource;
if (isFontIconURI(iconSource)) { if (isFontIconURI(iconSource)) {
@@ -705,7 +708,10 @@ export class BottomNavigation extends TabNavigationBase {
} }
public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: Font): void { public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: Font): void {
tabStripItem.nativeViewProtected.setTextSize(value.fontSize); if (value.fontSize) {
tabStripItem.nativeViewProtected.setTextSize(value.fontSize);
}
tabStripItem.nativeViewProtected.setTypeface(value.getAndroidTypeface()); tabStripItem.nativeViewProtected.setTypeface(value.getAndroidTypeface());
} }

View File

@@ -127,7 +127,7 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
const parent = <TabStrip>this.parent; const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent; const tabStripParent = parent && <TabNavigationBase>parent.parent;
return tabStripParent && (<any>tabStripParent).setTabBarIconColor(this, args.value); return tabStripParent && tabStripParent.setTabBarIconColor(this, args.value);
}); });
this.image.style.on("colorChange", this._imageColorHandler); this.image.style.on("colorChange", this._imageColorHandler);
@@ -135,7 +135,7 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
const parent = <TabStrip>this.parent; const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent; const tabStripParent = parent && <TabNavigationBase>parent.parent;
return tabStripParent && (<any>tabStripParent).setTabBarIconColor(this, args.value); return tabStripParent && tabStripParent.setTabBarIconColor(this, args.value);
}); });
this.image.style.on("fontInternalChange", this._imageFontHandler); this.image.style.on("fontInternalChange", this._imageFontHandler);
@@ -143,7 +143,7 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
const parent = <TabStrip>this.parent; const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent; const tabStripParent = parent && <TabNavigationBase>parent.parent;
return tabStripParent && (<any>tabStripParent).setTabBarIconColor(this, args.value); return tabStripParent && tabStripParent.setTabBarIconColor(this, args.value);
}); });
this.image.on("srcChange", this._imageSrcHandler); this.image.on("srcChange", this._imageSrcHandler);
} }

View File

@@ -689,6 +689,9 @@ export class Tabs extends TabsBase {
private getIcon(tabStripItem: TabStripItem): android.graphics.drawable.BitmapDrawable { private getIcon(tabStripItem: TabStripItem): android.graphics.drawable.BitmapDrawable {
const iconSource = tabStripItem.image && tabStripItem.image.src; const iconSource = tabStripItem.image && tabStripItem.image.src;
if (!iconSource) {
return null;
}
let is: ImageSource; let is: ImageSource;
if (isFontIconURI(iconSource)) { if (isFontIconURI(iconSource)) {
@@ -819,7 +822,9 @@ export class Tabs extends TabsBase {
} }
public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: Font): void { public setTabBarItemFontInternal(tabStripItem: TabStripItem, value: Font): void {
tabStripItem.nativeViewProtected.setTextSize(value.fontSize); if (value.fontSize) {
tabStripItem.nativeViewProtected.setTextSize(value.fontSize);
}
tabStripItem.nativeViewProtected.setTypeface(value.getAndroidTypeface()); tabStripItem.nativeViewProtected.setTypeface(value.getAndroidTypeface());
} }