Skip to content

Commit 8569b51

Browse files
vtrifonovvakrilov
andauthored
fix: return default tab background color when the background color is not explicitely set through css (#8240)
* fix: return default tab background color when the background color is not explicitely set through css * chore: update NativeScript.api.md * fix: do not cast return getTabBarBackgroundColor to ColorDrawable * chore: added comment and method check Co-authored-by: Alexander Vakrilov <alexander.vakrilov@gmail.com>
1 parent 4e48e68 commit 8569b51

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

api-reports/NativeScript.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,8 @@ export class TabContentItem extends ContentView {
21972197
export class TabNavigationBase extends View {
21982198
android: any /* android.view.View */;
21992199

2200+
getTabBarBackgroundArgbColor(): any
2201+
22002202
getTabBarBackgroundColor(): any
22012203

22022204
getTabBarColor(): any

nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,7 @@ export class BottomNavigation extends TabNavigationBase {
578578

579579
// BACKGROUND-COLOR
580580
const backgroundColor = tabStripItem.style.backgroundColor;
581-
if (backgroundColor) {
582-
tabItemSpec.backgroundColor = backgroundColor.android;
583-
}
581+
tabItemSpec.backgroundColor = backgroundColor ? backgroundColor.android : this.getTabBarBackgroundArgbColor();
584582

585583
// COLOR
586584
const color = titleLabel.style.color;

nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ export class TabNavigationBase extends View {
9090
*/
9191
getTabBarBackgroundColor(): any
9292

93+
/**
94+
* @private
95+
* Method is intended to be overridden by inheritors and used as "protected"
96+
*/
97+
getTabBarBackgroundArgbColor(): any
98+
9399
/**
94100
* @private
95101
* Method is intended to be overridden by inheritors and used as "protected"

nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ export class TabNavigationBase extends View implements TabNavigationBaseDefiniti
113113
return null;
114114
}
115115

116+
public getTabBarBackgroundArgbColor(): any {
117+
// This method is implemented only for Android
118+
const colorDrawable = this.getTabBarBackgroundColor();
119+
120+
return colorDrawable && colorDrawable.getColor && colorDrawable.getColor();
121+
}
122+
116123
public setTabBarBackgroundColor(value: any): void {
117124
// overridden by inheritors
118125
}

nativescript-core/ui/tabs/tabs.android.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,7 @@ export class Tabs extends TabsBase {
653653

654654
// BACKGROUND-COLOR
655655
const backgroundColor = tabStripItem.style.backgroundColor;
656-
if (backgroundColor) {
657-
tabItemSpec.backgroundColor = backgroundColor.android;
658-
}
656+
tabItemSpec.backgroundColor = backgroundColor ? backgroundColor.android : this.getTabBarBackgroundArgbColor();
659657

660658
// COLOR
661659
const color = nestedLabel.style.color;

0 commit comments

Comments
 (0)