mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
TabView color and selctedColors
This commit is contained in:
@ -1,15 +1,15 @@
|
|||||||
var observableModule = require("data/observable");
|
var observableModule = require("data/observable");
|
||||||
var vm = new observableModule.Observable();
|
var vm = new observableModule.Observable();
|
||||||
function onPageLoaded(args) {
|
export function onPageLoaded(args) {
|
||||||
var page = args.object;
|
var page = args.object;
|
||||||
vm.set("firstTitle", "fiiiirst");
|
vm.set("firstTitle", "fiiiirst");
|
||||||
vm.set("secondTitle", "secondTitle");
|
vm.set("secondTitle", "secondTitle");
|
||||||
vm.set("secondIcon", "res://icon");
|
vm.set("secondIcon", "res://icon");
|
||||||
page.bindingContext = vm;
|
page.bindingContext = vm;
|
||||||
}
|
}
|
||||||
exports.onPageLoaded = onPageLoaded;
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
function onTap() {
|
|
||||||
|
export function onTap() {
|
||||||
i++;
|
i++;
|
||||||
vm.set("firstTitle", "changed " + i);
|
vm.set("firstTitle", "changed " + i);
|
||||||
if (i === 3) {
|
if (i === 3) {
|
||||||
@ -19,5 +19,15 @@ function onTap() {
|
|||||||
vm.set("firstIcon", "");
|
vm.set("firstIcon", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.onTap = onTap;
|
|
||||||
//# sourceMappingURL=tab-view.js.map
|
export function setStyle(args) {
|
||||||
|
var page = args.object.actionBar.page;
|
||||||
|
|
||||||
|
page.css = "TabView { color: red; }";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearStyle(args) {
|
||||||
|
var page = args.object.actionBar.page;
|
||||||
|
|
||||||
|
page.css = "Page { background-color: red; }";
|
||||||
|
}
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<Page loaded="onPageLoaded">
|
<Page loaded="onPageLoaded">
|
||||||
<TabView>
|
<Page.actionBar>
|
||||||
|
<ActionBar title="Title" class="custom-action-bar">
|
||||||
|
<ActionBar.actionItems>
|
||||||
|
<ActionItem text="set" tap="setStyle"/>
|
||||||
|
<ActionItem text="clear" tap="clearStyle"/>
|
||||||
|
</ActionBar.actionItems>
|
||||||
|
</ActionBar>
|
||||||
|
</Page.actionBar>
|
||||||
|
<TabView selectedColor="green">
|
||||||
<TabView.items>
|
<TabView.items>
|
||||||
<TabViewItem title="{{ firstTitle }}" iconSource="{{ firstIcon }}">
|
<TabViewItem title="{{ firstTitle }}" iconSource="{{ firstIcon }}">
|
||||||
<TabViewItem.view>
|
<TabViewItem.view>
|
||||||
|
3
org.nativescript.widgets.d.ts
vendored
3
org.nativescript.widgets.d.ts
vendored
@ -152,6 +152,9 @@
|
|||||||
|
|
||||||
setItems(items: Array<TabItemSpec>, viewPager: android.support.v4.view.ViewPager): void;
|
setItems(items: Array<TabItemSpec>, viewPager: android.support.v4.view.ViewPager): void;
|
||||||
updateItemAt(position: number, itemSpec: TabItemSpec): void;
|
updateItemAt(position: number, itemSpec: TabItemSpec): void;
|
||||||
|
|
||||||
|
getTextViewForItemAt(index: number): android.widget.TextView;
|
||||||
|
getViewForItemAt(index: number): android.widget.LinearLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TabItemSpec {
|
export class TabItemSpec {
|
||||||
|
@ -8,6 +8,7 @@ import utils = require("utils/utils");
|
|||||||
import styleModule = require("./style");
|
import styleModule = require("./style");
|
||||||
import font = require("ui/styling/font");
|
import font = require("ui/styling/font");
|
||||||
import background = require("ui/styling/background");
|
import background = require("ui/styling/background");
|
||||||
|
import tabView = require("ui/tab-view");
|
||||||
var btn;
|
var btn;
|
||||||
|
|
||||||
global.moduleMerge(stylersCommon, exports);
|
global.moduleMerge(stylersCommon, exports);
|
||||||
@ -63,7 +64,7 @@ function onBackgroundOrBorderPropertyChanged(v: view.View) {
|
|||||||
(borderWidth + v.style.paddingTop) * density,
|
(borderWidth + v.style.paddingTop) * density,
|
||||||
(borderWidth + v.style.paddingRight) * density,
|
(borderWidth + v.style.paddingRight) * density,
|
||||||
(borderWidth + v.style.paddingBottom) * density
|
(borderWidth + v.style.paddingBottom) * density
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DefaultStyler implements definition.stylers.Styler {
|
export class DefaultStyler implements definition.stylers.Styler {
|
||||||
@ -125,7 +126,7 @@ export class DefaultStyler implements definition.stylers.Styler {
|
|||||||
private static setNativeLayoutParamsProperty(view: view.View, params: style.CommonLayoutParams): void {
|
private static setNativeLayoutParamsProperty(view: view.View, params: style.CommonLayoutParams): void {
|
||||||
var nativeView: android.view.View = view._nativeView;
|
var nativeView: android.view.View = view._nativeView;
|
||||||
var lp = DefaultStyler.getNativeLayoutParams(nativeView);
|
var lp = DefaultStyler.getNativeLayoutParams(nativeView);
|
||||||
|
|
||||||
lp.leftMargin = params.leftMargin * utils.layout.getDisplayDensity();
|
lp.leftMargin = params.leftMargin * utils.layout.getDisplayDensity();
|
||||||
lp.topMargin = params.topMargin * utils.layout.getDisplayDensity();
|
lp.topMargin = params.topMargin * utils.layout.getDisplayDensity();
|
||||||
lp.rightMargin = params.rightMargin * utils.layout.getDisplayDensity();
|
lp.rightMargin = params.rightMargin * utils.layout.getDisplayDensity();
|
||||||
@ -160,7 +161,7 @@ export class DefaultStyler implements definition.stylers.Styler {
|
|||||||
|
|
||||||
case enums.HorizontalAlignment.stretch:
|
case enums.HorizontalAlignment.stretch:
|
||||||
gravity |= android.view.Gravity.FILL_HORIZONTAL;
|
gravity |= android.view.Gravity.FILL_HORIZONTAL;
|
||||||
// If width is not specified set it as MATCH_PARENT
|
// If width is not specified set it as MATCH_PARENT
|
||||||
if (width < 0) {
|
if (width < 0) {
|
||||||
width = -1;
|
width = -1;
|
||||||
}
|
}
|
||||||
@ -198,7 +199,7 @@ export class DefaultStyler implements definition.stylers.Styler {
|
|||||||
lp.gravity = gravity;
|
lp.gravity = gravity;
|
||||||
lp.width = width;
|
lp.width = width;
|
||||||
lp.height = height;
|
lp.height = height;
|
||||||
|
|
||||||
nativeView.setLayoutParams(lp);
|
nativeView.setLayoutParams(lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,7 +603,7 @@ export class SearchBarStyler implements definition.stylers.Styler {
|
|||||||
|
|
||||||
private static _getSearchViewTextView(bar: android.widget.SearchView): android.widget.TextView {
|
private static _getSearchViewTextView(bar: android.widget.SearchView): android.widget.TextView {
|
||||||
var id = bar.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
|
var id = bar.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
|
||||||
return <android.widget.TextView> bar.findViewById(id);
|
return <android.widget.TextView>bar.findViewById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _changeSearchViewTextColor(bar: android.widget.SearchView, color: number) {
|
private static _changeSearchViewTextColor(bar: android.widget.SearchView, color: number) {
|
||||||
@ -614,7 +615,7 @@ export class SearchBarStyler implements definition.stylers.Styler {
|
|||||||
|
|
||||||
private static _changeSearchViewPlateBackgroundColor(bar: android.widget.SearchView, color: number) {
|
private static _changeSearchViewPlateBackgroundColor(bar: android.widget.SearchView, color: number) {
|
||||||
var id = bar.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
|
var id = bar.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
|
||||||
var textView = <android.view.View> bar.findViewById(id);
|
var textView = <android.view.View>bar.findViewById(id);
|
||||||
if (textView) {
|
if (textView) {
|
||||||
textView.setBackgroundColor(color);
|
textView.setBackgroundColor(color);
|
||||||
}
|
}
|
||||||
@ -643,6 +644,51 @@ export class ActionBarStyler implements definition.stylers.Styler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class TabViewStyler implements definition.stylers.Styler {
|
||||||
|
// color
|
||||||
|
private static setColorProperty(view: view.View, newValue: any) {
|
||||||
|
var tab = <tabView.TabView>view;
|
||||||
|
var count = tab.items ? tab.items.length : 0;
|
||||||
|
var tabLayout = tab._getAndroidTabView();
|
||||||
|
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
tabLayout.getTextViewForItemAt(i).setTextColor(newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||||
|
if (types.isNullOrUndefined(nativeValue)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tab = <tabView.TabView>view;
|
||||||
|
var count = tab.items ? tab.items.length : 0;
|
||||||
|
var tabLayout = tab._getAndroidTabView();
|
||||||
|
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
tabLayout.getTextViewForItemAt(i).setTextColor(nativeValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static getColorProperty(view: view.View): any {
|
||||||
|
var tab = <tabView.TabView>view;
|
||||||
|
var tv: android.widget.TextView = tab._getAndroidTabView().getTextViewForItemAt(0);
|
||||||
|
if (tv) {
|
||||||
|
return tv.getTextColors().getDefaultColor();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static registerHandlers() {
|
||||||
|
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||||
|
TabViewStyler.setColorProperty,
|
||||||
|
TabViewStyler.resetColorProperty,
|
||||||
|
TabViewStyler.getColorProperty), "TabView");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Register all styler at the end.
|
// Register all styler at the end.
|
||||||
export function _registerDefaultStylers() {
|
export function _registerDefaultStylers() {
|
||||||
style.registerNoStylingClass("Frame");
|
style.registerNoStylingClass("Frame");
|
||||||
@ -653,4 +699,5 @@ export function _registerDefaultStylers() {
|
|||||||
SegmentedBarStyler.registerHandlers();
|
SegmentedBarStyler.registerHandlers();
|
||||||
SearchBarStyler.registerHandlers();
|
SearchBarStyler.registerHandlers();
|
||||||
ActionBarStyler.registerHandlers();
|
ActionBarStyler.registerHandlers();
|
||||||
|
TabViewStyler.registerHandlers();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import enums = require("ui/enums");
|
|||||||
import font = require("ui/styling/font");
|
import font = require("ui/styling/font");
|
||||||
import background = require("ui/styling/background");
|
import background = require("ui/styling/background");
|
||||||
import frame = require("ui/frame");
|
import frame = require("ui/frame");
|
||||||
|
import tabView = require("ui/tab-view");
|
||||||
|
|
||||||
global.moduleMerge(stylersCommon, exports);
|
global.moduleMerge(stylersCommon, exports);
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ export class DefaultStyler implements definition.stylers.Styler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static getBorderWidthProperty(view: view.View): any {
|
private static getBorderWidthProperty(view: view.View): any {
|
||||||
if (view._nativeView instanceof UIView){
|
if (view._nativeView instanceof UIView) {
|
||||||
return (<UIView>view._nativeView).layer.borderWidth;
|
return (<UIView>view._nativeView).layer.borderWidth;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -500,6 +501,25 @@ export class ActionBarStyler implements definition.stylers.Styler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class TabViewStyler implements definition.stylers.Styler {
|
||||||
|
// color
|
||||||
|
private static setColorProperty(view: view.View, newValue: any) {
|
||||||
|
var tab = <tabView.TabView>view;
|
||||||
|
tab._updateIOSTabBarColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||||
|
var tab = <tabView.TabView>view;
|
||||||
|
tab._updateIOSTabBarColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static registerHandlers() {
|
||||||
|
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||||
|
TabViewStyler.setColorProperty,
|
||||||
|
TabViewStyler.resetColorProperty), "TabView");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setTextAlignment(view: TextUIView, value: string) {
|
function setTextAlignment(view: TextUIView, value: string) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case enums.TextAlignment.left:
|
case enums.TextAlignment.left:
|
||||||
@ -526,4 +546,5 @@ export function _registerDefaultStylers() {
|
|||||||
SegmentedBarStyler.registerHandlers();
|
SegmentedBarStyler.registerHandlers();
|
||||||
SearchBarStyler.registerHandlers();
|
SearchBarStyler.registerHandlers();
|
||||||
ActionBarStyler.registerHandlers();
|
ActionBarStyler.registerHandlers();
|
||||||
|
TabViewStyler.registerHandlers();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import proxy = require("ui/core/proxy");
|
|||||||
import types = require("utils/types");
|
import types = require("utils/types");
|
||||||
import trace = require("trace");
|
import trace = require("trace");
|
||||||
import bindable = require("ui/core/bindable");
|
import bindable = require("ui/core/bindable");
|
||||||
|
import color = require("color");
|
||||||
|
|
||||||
export var traceCategory = "TabView";
|
export var traceCategory = "TabView";
|
||||||
|
|
||||||
@ -56,6 +57,7 @@ export class TabViewItem extends bindable.Bindable implements definition.TabView
|
|||||||
var TAB_VIEW = "TabView";
|
var TAB_VIEW = "TabView";
|
||||||
var ITEMS = "items";
|
var ITEMS = "items";
|
||||||
var SELECTED_INDEX = "selectedIndex";
|
var SELECTED_INDEX = "selectedIndex";
|
||||||
|
var SELECTED_COLOR = "selectedColor";
|
||||||
|
|
||||||
export module knownCollections {
|
export module knownCollections {
|
||||||
export var items = "items";
|
export var items = "items";
|
||||||
@ -74,6 +76,13 @@ var selectedIndexProperty = new dependencyObservable.Property(
|
|||||||
undefined,
|
undefined,
|
||||||
dependencyObservable.PropertyMetadataSettings.AffectsLayout));
|
dependencyObservable.PropertyMetadataSettings.AffectsLayout));
|
||||||
|
|
||||||
|
var selectedColorProperty = new dependencyObservable.Property(
|
||||||
|
SELECTED_COLOR,
|
||||||
|
TAB_VIEW,
|
||||||
|
new proxy.PropertyMetadata(
|
||||||
|
undefined,
|
||||||
|
dependencyObservable.PropertyMetadataSettings.None));
|
||||||
|
|
||||||
(<proxy.PropertyMetadata>selectedIndexProperty.metadata).onSetNativeValue = function (data: dependencyObservable.PropertyChangeData) {
|
(<proxy.PropertyMetadata>selectedIndexProperty.metadata).onSetNativeValue = function (data: dependencyObservable.PropertyChangeData) {
|
||||||
var tabView = <TabView>data.object;
|
var tabView = <TabView>data.object;
|
||||||
tabView._onSelectedIndexPropertyChangedSetNativeValue(data);
|
tabView._onSelectedIndexPropertyChangedSetNativeValue(data);
|
||||||
@ -87,6 +96,7 @@ var selectedIndexProperty = new dependencyObservable.Property(
|
|||||||
export class TabView extends view.View implements definition.TabView, view.AddArrayFromBuilder {
|
export class TabView extends view.View implements definition.TabView, view.AddArrayFromBuilder {
|
||||||
public static itemsProperty = itemsProperty;
|
public static itemsProperty = itemsProperty;
|
||||||
public static selectedIndexProperty = selectedIndexProperty;
|
public static selectedIndexProperty = selectedIndexProperty;
|
||||||
|
public static selectedColorProperty = selectedColorProperty;
|
||||||
public static selectedIndexChangedEvent = "selectedIndexChanged";
|
public static selectedIndexChangedEvent = "selectedIndexChanged";
|
||||||
|
|
||||||
public _addArrayFromBuilder(name: string, value: Array<any>) {
|
public _addArrayFromBuilder(name: string, value: Array<any>) {
|
||||||
@ -159,6 +169,14 @@ export class TabView extends view.View implements definition.TabView, view.AddAr
|
|||||||
this._setValue(TabView.selectedIndexProperty, value);
|
this._setValue(TabView.selectedIndexProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get selectedColor(): color.Color {
|
||||||
|
return this._getValue(TabView.selectedColorProperty);
|
||||||
|
}
|
||||||
|
set selectedColor(value: color.Color) {
|
||||||
|
this._setValue(TabView.selectedColorProperty,
|
||||||
|
value instanceof color.Color ? value : new color.Color(<any>value));
|
||||||
|
}
|
||||||
|
|
||||||
public _onSelectedIndexPropertyChangedSetNativeValue(data: dependencyObservable.PropertyChangeData) {
|
public _onSelectedIndexPropertyChangedSetNativeValue(data: dependencyObservable.PropertyChangeData) {
|
||||||
var index = this.selectedIndex;
|
var index = this.selectedIndex;
|
||||||
if (types.isUndefined(index)) {
|
if (types.isUndefined(index)) {
|
||||||
@ -233,4 +251,13 @@ export class TabView extends view.View implements definition.TabView, view.AddAr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _getAndroidTabView(): org.nativescript.widgets.TabLayout {
|
||||||
|
// Android specific
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
public _updateIOSTabBarColors() {
|
||||||
|
// iOS sepcific
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,6 +6,8 @@ import trace = require("trace");
|
|||||||
import types = require("utils/types");
|
import types = require("utils/types");
|
||||||
import utils = require("utils/utils");
|
import utils = require("utils/utils");
|
||||||
import imageSource = require("image-source");
|
import imageSource = require("image-source");
|
||||||
|
import proxy = require("ui/core/proxy");
|
||||||
|
import color = require("color");
|
||||||
|
|
||||||
var VIEWS_STATES = "_viewStates";
|
var VIEWS_STATES = "_viewStates";
|
||||||
var ACCENT_COLOR = "colorAccent";
|
var ACCENT_COLOR = "colorAccent";
|
||||||
@ -140,6 +142,14 @@ class PageChangedListener extends android.support.v4.view.ViewPager.SimpleOnPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectedColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
var tabLayout = (<TabView>data.object)._getAndroidTabView();
|
||||||
|
if (tabLayout && data.newValue instanceof color.Color) {
|
||||||
|
tabLayout.setSelectedIndicatorColors([data.newValue.android]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(<proxy.PropertyMetadata>common.TabView.selectedColorProperty.metadata).onSetNativeValue = selectedColorPropertyChanged;
|
||||||
|
|
||||||
export class TabView extends common.TabView {
|
export class TabView extends common.TabView {
|
||||||
private _grid: org.nativescript.widgets.GridLayout;
|
private _grid: org.nativescript.widgets.GridLayout;
|
||||||
private _tabLayout: org.nativescript.widgets.TabLayout;
|
private _tabLayout: org.nativescript.widgets.TabLayout;
|
||||||
@ -278,4 +288,8 @@ export class TabView extends common.TabView {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _getAndroidTabView(): org.nativescript.widgets.TabLayout {
|
||||||
|
return this._tabLayout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
14
ui/tab-view/tab-view.d.ts
vendored
14
ui/tab-view/tab-view.d.ts
vendored
@ -6,6 +6,7 @@ declare module "ui/tab-view" {
|
|||||||
import dependencyObservable = require("ui/core/dependency-observable");
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
import observable = require("data/observable");
|
import observable = require("data/observable");
|
||||||
import bindable = require("ui/core/bindable");
|
import bindable = require("ui/core/bindable");
|
||||||
|
import color = require("color");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a tab view entry.
|
* Represents a tab view entry.
|
||||||
@ -48,6 +49,7 @@ declare module "ui/tab-view" {
|
|||||||
class TabView extends view.View {
|
class TabView extends view.View {
|
||||||
public static itemsProperty: dependencyObservable.Property;
|
public static itemsProperty: dependencyObservable.Property;
|
||||||
public static selectedIndexProperty: dependencyObservable.Property;
|
public static selectedIndexProperty: dependencyObservable.Property;
|
||||||
|
public static selectedColorProperty: dependencyObservable.Property;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets or sets the items of the TabView.
|
* Gets or sets the items of the TabView.
|
||||||
@ -59,6 +61,11 @@ declare module "ui/tab-view" {
|
|||||||
*/
|
*/
|
||||||
selectedIndex: number;
|
selectedIndex: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the color used for selected item.
|
||||||
|
*/
|
||||||
|
selectedColor: 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.
|
* 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.
|
||||||
*/
|
*/
|
||||||
@ -86,5 +93,10 @@ declare module "ui/tab-view" {
|
|||||||
* Raised when the selected index changes.
|
* Raised when the selected index changes.
|
||||||
*/
|
*/
|
||||||
on(event: "selectedIndexChanged", callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
|
on(event: "selectedIndexChanged", callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
|
||||||
|
|
||||||
|
//@private
|
||||||
|
_getAndroidTabView(): org.nativescript.widgets.TabLayout;
|
||||||
|
_updateIOSTabBarColors();
|
||||||
|
//@endprivate
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,6 +7,8 @@ import uiUtils = require("ui/utils");
|
|||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
import imageSource = require("image-source");
|
import imageSource = require("image-source");
|
||||||
import types = require("utils/types");
|
import types = require("utils/types");
|
||||||
|
import proxy = require("ui/core/proxy");
|
||||||
|
import color = require("color");
|
||||||
|
|
||||||
global.moduleMerge(common, exports);
|
global.moduleMerge(common, exports);
|
||||||
|
|
||||||
@ -89,11 +91,21 @@ export class TabViewItem extends common.TabViewItem {
|
|||||||
(<any>tabBarItem).titlePositionAdjustment = { horizontal: 0, vertical: -20 };
|
(<any>tabBarItem).titlePositionAdjustment = { horizontal: 0, vertical: -20 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var states = getTitleAttributesForStates(this._parent);
|
||||||
|
tabBarItem.setTitleTextAttributesForState(states.normalState, UIControlState.UIControlStateNormal);
|
||||||
|
tabBarItem.setTitleTextAttributesForState(states.selectedState, UIControlState.UIControlStateSelected);
|
||||||
this._controller.tabBarItem = tabBarItem;
|
this._controller.tabBarItem = tabBarItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectedColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
|
var tabView = <TabView>data.object;
|
||||||
|
tabView._updateIOSTabBarColors();
|
||||||
|
}
|
||||||
|
(<proxy.PropertyMetadata>common.TabView.selectedColorProperty.metadata).onSetNativeValue = selectedColorPropertyChanged;
|
||||||
|
|
||||||
export class TabView extends common.TabView {
|
export class TabView extends common.TabView {
|
||||||
private _ios: UITabBarControllerImpl;
|
private _ios: UITabBarControllerImpl;
|
||||||
private _delegate: UITabBarControllerDelegateImpl;
|
private _delegate: UITabBarControllerDelegateImpl;
|
||||||
@ -124,7 +136,7 @@ export class TabView extends common.TabView {
|
|||||||
super.onUnloaded();
|
super.onUnloaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
get ios(): UIViewController {
|
get ios(): UITabBarController {
|
||||||
return this._ios;
|
return this._ios;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,4 +307,39 @@ export class TabView extends common.TabView {
|
|||||||
(widthMode === utils.layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : width,
|
(widthMode === utils.layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : width,
|
||||||
(heightMode === utils.layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : height));
|
(heightMode === utils.layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : height));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public _updateIOSTabBarColors() {
|
||||||
|
if (!this.items) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tabBar = this.ios.tabBar;
|
||||||
|
var states = getTitleAttributesForStates(this);
|
||||||
|
|
||||||
|
for (var i = 0; i < this.items.length; i++) {
|
||||||
|
var item = <UITabBarItem>tabBar.items[i];
|
||||||
|
item.setTitleTextAttributesForState(states.normalState, UIControlState.UIControlStateNormal);
|
||||||
|
item.setTitleTextAttributesForState(states.selectedState, UIControlState.UIControlStateSelected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTitleAttributesForStates(tabView: TabView): { normalState: any, selectedState: any } {
|
||||||
|
var normalState = <any>{};
|
||||||
|
if (tabView.color instanceof color.Color) {
|
||||||
|
normalState[UITextAttributeTextColor] = tabView.color.ios;
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedState = <any>{};
|
||||||
|
if (tabView.selectedColor instanceof color.Color) {
|
||||||
|
selectedState[UITextAttributeTextColor] = tabView.selectedColor.ios;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
selectedState[UITextAttributeTextColor] = tabView.ios.tabBar.tintColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
normalState: normalState,
|
||||||
|
selectedState: selectedState
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user