From 8569b51a9a0edb6096953042518195c906f77150 Mon Sep 17 00:00:00 2001 From: Vasil Trifonov Date: Tue, 14 Jan 2020 15:53:26 +0200 Subject: [PATCH] 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 --- api-reports/NativeScript.api.md | 2 ++ .../ui/bottom-navigation/bottom-navigation.android.ts | 4 +--- .../tab-navigation-base/tab-navigation-base.d.ts | 6 ++++++ .../tab-navigation-base/tab-navigation-base.ts | 7 +++++++ nativescript-core/ui/tabs/tabs.android.ts | 4 +--- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/api-reports/NativeScript.api.md b/api-reports/NativeScript.api.md index f6f2c8e68..fb7e0cbb4 100644 --- a/api-reports/NativeScript.api.md +++ b/api-reports/NativeScript.api.md @@ -2197,6 +2197,8 @@ export class TabContentItem extends ContentView { export class TabNavigationBase extends View { android: any /* android.view.View */; + getTabBarBackgroundArgbColor(): any + getTabBarBackgroundColor(): any getTabBarColor(): any diff --git a/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts b/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts index 077a4096c..ce3bfd17d 100644 --- a/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts +++ b/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts @@ -578,9 +578,7 @@ export class BottomNavigation extends TabNavigationBase { // BACKGROUND-COLOR const backgroundColor = tabStripItem.style.backgroundColor; - if (backgroundColor) { - tabItemSpec.backgroundColor = backgroundColor.android; - } + tabItemSpec.backgroundColor = backgroundColor ? backgroundColor.android : this.getTabBarBackgroundArgbColor(); // COLOR const color = titleLabel.style.color; diff --git a/nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.d.ts b/nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.d.ts index 1a6b24418..7440e23e6 100644 --- a/nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.d.ts +++ b/nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.d.ts @@ -90,6 +90,12 @@ export class TabNavigationBase extends View { */ getTabBarBackgroundColor(): any + /** + * @private + * Method is intended to be overridden by inheritors and used as "protected" + */ + getTabBarBackgroundArgbColor(): any + /** * @private * Method is intended to be overridden by inheritors and used as "protected" diff --git a/nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.ts b/nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.ts index eb8d96ed0..ee035bf1f 100644 --- a/nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.ts +++ b/nativescript-core/ui/tab-navigation-base/tab-navigation-base/tab-navigation-base.ts @@ -113,6 +113,13 @@ export class TabNavigationBase extends View implements TabNavigationBaseDefiniti return null; } + public getTabBarBackgroundArgbColor(): any { + // This method is implemented only for Android + const colorDrawable = this.getTabBarBackgroundColor(); + + return colorDrawable && colorDrawable.getColor && colorDrawable.getColor(); + } + public setTabBarBackgroundColor(value: any): void { // overridden by inheritors } diff --git a/nativescript-core/ui/tabs/tabs.android.ts b/nativescript-core/ui/tabs/tabs.android.ts index 3659eed9a..6008b7980 100644 --- a/nativescript-core/ui/tabs/tabs.android.ts +++ b/nativescript-core/ui/tabs/tabs.android.ts @@ -653,9 +653,7 @@ export class Tabs extends TabsBase { // BACKGROUND-COLOR const backgroundColor = tabStripItem.style.backgroundColor; - if (backgroundColor) { - tabItemSpec.backgroundColor = backgroundColor.android; - } + tabItemSpec.backgroundColor = backgroundColor ? backgroundColor.android : this.getTabBarBackgroundArgbColor(); // COLOR const color = nestedLabel.style.color;