mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: add background color css to tab strip (#7414)
This commit is contained in:
@@ -5,7 +5,7 @@ import { TabContentItem } from "../tab-navigation-base/tab-content-item";
|
||||
|
||||
// Requires
|
||||
import { TabNavigationBase, itemsProperty, selectedIndexProperty, tabStripProperty } from "../tab-navigation-base/tab-navigation-base";
|
||||
import { CSSType } from "../core/view";
|
||||
import { CSSType, Color } from "../core/view";
|
||||
import { Frame } from "../frame";
|
||||
import { RESOURCE_PREFIX, ad, layout } from "../../utils/utils";
|
||||
import { fromFileOrResource } from "../../image-source";
|
||||
@@ -352,6 +352,11 @@ export class BottomNavigation extends TabNavigationBase {
|
||||
});
|
||||
|
||||
this._bottomNavigationBar.setItems(tabItems);
|
||||
this.tabStrip.setNativeView(this._bottomNavigationBar);
|
||||
this.tabStrip.items.forEach((item, i, arr) => {
|
||||
const tv = this._bottomNavigationBar.getTextViewForItemAt(i);
|
||||
item.setNativeView(tv);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,6 +364,18 @@ export class BottomNavigation extends TabNavigationBase {
|
||||
this._bottomNavigationBar.updateItemAt(index, spec);
|
||||
}
|
||||
|
||||
public getTabBarBackgroundColor(): android.graphics.drawable.Drawable {
|
||||
return this._bottomNavigationBar.getBackground();
|
||||
}
|
||||
|
||||
public setTabBarBackgroundColor(value: android.graphics.drawable.Drawable | Color): void {
|
||||
if (value instanceof Color) {
|
||||
this._bottomNavigationBar.setBackgroundColor(value.android);
|
||||
} else {
|
||||
this._bottomNavigationBar.setBackground(tryCloneDrawable(value, this.nativeViewProtected.getResources));
|
||||
}
|
||||
}
|
||||
|
||||
[selectedIndexProperty.setNative](value: number) {
|
||||
// const smoothScroll = false;
|
||||
|
||||
@@ -383,3 +400,14 @@ export class BottomNavigation extends TabNavigationBase {
|
||||
this.setAdapterItems([]);
|
||||
}
|
||||
}
|
||||
|
||||
function tryCloneDrawable(value: android.graphics.drawable.Drawable, resources: android.content.res.Resources): android.graphics.drawable.Drawable {
|
||||
if (value) {
|
||||
const constantState = value.getConstantState();
|
||||
if (constantState) {
|
||||
return constantState.newDrawable(resources);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user