mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
ActionBar and TabView colors
This commit is contained in:
@@ -58,6 +58,7 @@ var TAB_VIEW = "TabView";
|
||||
var ITEMS = "items";
|
||||
var SELECTED_INDEX = "selectedIndex";
|
||||
var SELECTED_COLOR = "selectedColor";
|
||||
var TABS_BACKGROUND_COLOR = "tabsBackgroundColor";
|
||||
|
||||
export module knownCollections {
|
||||
export var items = "items";
|
||||
@@ -83,6 +84,13 @@ var selectedColorProperty = new dependencyObservable.Property(
|
||||
undefined,
|
||||
dependencyObservable.PropertyMetadataSettings.None));
|
||||
|
||||
var tabsBackgroundColorProperty = new dependencyObservable.Property(
|
||||
TABS_BACKGROUND_COLOR,
|
||||
TAB_VIEW,
|
||||
new proxy.PropertyMetadata(
|
||||
undefined,
|
||||
dependencyObservable.PropertyMetadataSettings.None));
|
||||
|
||||
(<proxy.PropertyMetadata>selectedIndexProperty.metadata).onSetNativeValue = function (data: dependencyObservable.PropertyChangeData) {
|
||||
var tabView = <TabView>data.object;
|
||||
tabView._onSelectedIndexPropertyChangedSetNativeValue(data);
|
||||
@@ -97,6 +105,7 @@ export class TabView extends view.View implements definition.TabView, view.AddAr
|
||||
public static itemsProperty = itemsProperty;
|
||||
public static selectedIndexProperty = selectedIndexProperty;
|
||||
public static selectedColorProperty = selectedColorProperty;
|
||||
public static tabsBackgroundColorProperty = tabsBackgroundColorProperty;
|
||||
public static selectedIndexChangedEvent = "selectedIndexChanged";
|
||||
|
||||
public _addArrayFromBuilder(name: string, value: Array<any>) {
|
||||
@@ -177,6 +186,14 @@ export class TabView extends view.View implements definition.TabView, view.AddAr
|
||||
value instanceof color.Color ? value : new color.Color(<any>value));
|
||||
}
|
||||
|
||||
get tabsBackgroundColor(): color.Color {
|
||||
return this._getValue(TabView.tabsBackgroundColorProperty);
|
||||
}
|
||||
set tabsBackgroundColor(value: color.Color) {
|
||||
this._setValue(TabView.tabsBackgroundColorProperty,
|
||||
value instanceof color.Color ? value : new color.Color(<any>value));
|
||||
}
|
||||
|
||||
public _onSelectedIndexPropertyChangedSetNativeValue(data: dependencyObservable.PropertyChangeData) {
|
||||
var index = this.selectedIndex;
|
||||
if (types.isUndefined(index)) {
|
||||
|
||||
@@ -150,6 +150,14 @@ function selectedColorPropertyChanged(data: dependencyObservable.PropertyChangeD
|
||||
}
|
||||
(<proxy.PropertyMetadata>common.TabView.selectedColorProperty.metadata).onSetNativeValue = selectedColorPropertyChanged;
|
||||
|
||||
function tabsBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var tabLayout = (<TabView>data.object)._getAndroidTabView();
|
||||
if (tabLayout && data.newValue instanceof color.Color) {
|
||||
tabLayout.setBackgroundColor(data.newValue.android);
|
||||
}
|
||||
}
|
||||
(<proxy.PropertyMetadata>common.TabView.tabsBackgroundColorProperty.metadata).onSetNativeValue = tabsBackgroundColorPropertyChanged;
|
||||
|
||||
export class TabView extends common.TabView {
|
||||
private _grid: org.nativescript.widgets.GridLayout;
|
||||
private _tabLayout: org.nativescript.widgets.TabLayout;
|
||||
|
||||
5
ui/tab-view/tab-view.d.ts
vendored
5
ui/tab-view/tab-view.d.ts
vendored
@@ -66,6 +66,11 @@ declare module "ui/tab-view" {
|
||||
*/
|
||||
selectedColor: color.Color;
|
||||
|
||||
/**
|
||||
* Gets or sets the color used for background of the tab items.
|
||||
*/
|
||||
tabsBackgroundColor: color.Color;
|
||||
|
||||
/**
|
||||
* Gets the native [android widget](http://developer.android.com/reference/android/support/v4/view/ViewPager.html) that represents the user interface for this component. Valid only when running on Android OS.
|
||||
*/
|
||||
|
||||
@@ -105,6 +105,14 @@ function selectedColorPropertyChanged(data: dependencyObservable.PropertyChangeD
|
||||
}
|
||||
(<proxy.PropertyMetadata>common.TabView.selectedColorProperty.metadata).onSetNativeValue = selectedColorPropertyChanged;
|
||||
|
||||
function tabsBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var tabView = <TabView>data.object;
|
||||
if (data.newValue instanceof color.Color) {
|
||||
tabView.ios.tabBar.barTintColor = data.newValue.ios;
|
||||
}
|
||||
}
|
||||
(<proxy.PropertyMetadata>common.TabView.tabsBackgroundColorProperty.metadata).onSetNativeValue = tabsBackgroundColorPropertyChanged;
|
||||
|
||||
export class TabView extends common.TabView {
|
||||
private _ios: UITabBarControllerImpl;
|
||||
private _delegate: UITabBarControllerDelegateImpl;
|
||||
@@ -179,6 +187,8 @@ export class TabView extends common.TabView {
|
||||
var newControllers: NSMutableArray = NSMutableArray.alloc().initWithCapacity(length);
|
||||
var newController: UIViewController;
|
||||
|
||||
var states = getTitleAttributesForStates(this);
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
item = <TabViewItem>newItems[i];
|
||||
|
||||
@@ -205,6 +215,9 @@ export class TabView extends common.TabView {
|
||||
(<any>tabBarItem).titlePositionAdjustment = { horizontal: 0, vertical: -20 };
|
||||
}
|
||||
}
|
||||
tabBarItem.setTitleTextAttributesForState(states.normalState, UIControlState.UIControlStateNormal);
|
||||
tabBarItem.setTitleTextAttributesForState(states.selectedState, UIControlState.UIControlStateSelected);
|
||||
|
||||
newController.tabBarItem = tabBarItem;
|
||||
newControllers.addObject(newController);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user