mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
@ -1,31 +1,38 @@
|
||||
import * as tabViewModule from "tns-core-modules/ui/tab-view";
|
||||
import { TabView } from "tns-core-modules/ui/tab-view";
|
||||
|
||||
export function getNativeTabCount(tabView: tabViewModule.TabView): number {
|
||||
var pagerAdapter: android.support.v4.view.PagerAdapter = (<any>tabView)._pagerAdapter;
|
||||
export function getNativeTabCount(tabView: TabView): number {
|
||||
const pagerAdapter: android.support.v4.view.PagerAdapter = (<any>tabView)._pagerAdapter;
|
||||
return pagerAdapter ? pagerAdapter.getCount() : 0;
|
||||
}
|
||||
|
||||
export function selectNativeTab(tabView: tabViewModule.TabView, index: number): void {
|
||||
var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
|
||||
export function selectNativeTab(tabView: TabView, index: number): void {
|
||||
const viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
|
||||
if (viewPager) {
|
||||
viewPager.setCurrentItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
export function getNativeSelectedIndex(tabView: tabViewModule.TabView): number {
|
||||
var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
|
||||
export function getNativeSelectedIndex(tabView: TabView): number {
|
||||
const viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
|
||||
return viewPager ? viewPager.getCurrentItem() : -1;
|
||||
}
|
||||
|
||||
export function getNativeFont(tabView: tabViewModule.TabView): any {
|
||||
var tv: android.widget.TextView = (<org.nativescript.widgets.TabLayout>(<any>tabView)._tabLayout).getTextViewForItemAt(0);
|
||||
if (tv) {
|
||||
return {
|
||||
typeface: tv.getTypeface(),
|
||||
size: tv.getTextSize()
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
export function getNativeFont(tabView: TabView): any {
|
||||
const tv: android.widget.TextView = (<org.nativescript.widgets.TabLayout>(<any>tabView)._tabLayout).getTextViewForItemAt(0);
|
||||
if (tv) {
|
||||
return {
|
||||
typeface: tv.getTypeface(),
|
||||
size: tv.getTextSize()
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getOriginalFont(tabView: TabView): any {
|
||||
const tv: android.widget.TextView = (<org.nativescript.widgets.TabLayout>(<any>tabView)._tabLayout).getTextViewForItemAt(0);
|
||||
return {
|
||||
typeface: tv.getTypeface(),
|
||||
size: tv.getTextSize()
|
||||
}
|
||||
}
|
11
tests/app/ui/tab-view/tab-view-tests-native.d.ts
vendored
11
tests/app/ui/tab-view/tab-view-tests-native.d.ts
vendored
@ -1,7 +1,8 @@
|
||||
//@private
|
||||
import * as tabViewModule from "tns-core-modules/ui/tab-view";
|
||||
import { TabView } from "tns-core-modules/ui/tab-view";
|
||||
|
||||
export declare function getNativeTabCount(tabView: tabViewModule.TabView): number;
|
||||
export declare function selectNativeTab(tabView: tabViewModule.TabView, index: number): void;
|
||||
export declare function getNativeSelectedIndex(tabView: tabViewModule.TabView): number;
|
||||
export declare function getNativeFont(tabView: tabViewModule.TabView): any;
|
||||
export function getNativeTabCount(tabView: TabView): number;
|
||||
export function selectNativeTab(tabView: TabView, index: number): void;
|
||||
export function getNativeSelectedIndex(tabView: TabView): number;
|
||||
export function getNativeFont(tabView: TabView): any;
|
||||
export function getOriginalFont(tabView: TabView): any;
|
@ -19,20 +19,18 @@ export function getNativeSelectedIndex(tabView: tabViewModule.TabView): number {
|
||||
return tabView.ios.selectedIndex;
|
||||
}
|
||||
|
||||
export function getNativeFont(tabView: tabViewModule.TabView): any {
|
||||
let tabBar = <UITabBar>tabView.ios.tabBar;
|
||||
let currentFont;
|
||||
|
||||
export function getNativeFont(tabView: tabViewModule.TabView): UIFont {
|
||||
const tabBar = <UITabBar>tabView.ios.tabBar;
|
||||
if (tabBar.items.count > 0) {
|
||||
let currentAttrs = tabBar.items[0].titleTextAttributesForState(UIControlState.Normal);
|
||||
const currentAttrs = tabBar.items[0].titleTextAttributesForState(UIControlState.Normal);
|
||||
if (currentAttrs) {
|
||||
currentFont = currentAttrs.objectForKey(NSFontAttributeName);
|
||||
return currentAttrs.objectForKey(NSFontAttributeName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentFont) {
|
||||
currentFont = UIFont.systemFontOfSize(getter(UIFont, UIFont.labelFontSize));
|
||||
}
|
||||
|
||||
return currentFont;
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getOriginalFont(tabView: tabViewModule.TabView): UIFont {
|
||||
return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
|
||||
}
|
@ -290,54 +290,35 @@ export class TabViewTest extends testModule.UITest<tabViewModule.TabView> {
|
||||
}
|
||||
|
||||
public test_FontIsReappliedWhenTabItemsChange = function () {
|
||||
// let fontToString = (font: any): string => {
|
||||
// if (this.testView.ios){
|
||||
// return font.toString();
|
||||
// }
|
||||
// else {
|
||||
// return `${font.typeface} ${font.size}`;
|
||||
// }
|
||||
// }
|
||||
|
||||
let assertFontsAreEqual = (actual: any, expected: any, message?: string) => {
|
||||
const assertFontsAreEqual = (actual: any, expected: any, message?: string) => {
|
||||
if (this.testView.ios) {
|
||||
TKUnit.assertEqual(actual, expected, message);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
TKUnit.assertEqual(actual.typeface, expected.typeface, `${message} [typeface]`);
|
||||
TKUnit.assertEqual(actual.size, expected.size, `${message} [size]`);
|
||||
}
|
||||
}
|
||||
|
||||
//console.log(`>>>>>>>>>>>>> CREATE 3 ITEMS`);
|
||||
this.testView.items = this._createItems(1);
|
||||
this.waitUntilTestElementIsLoaded();
|
||||
|
||||
let originalFont = tabViewTestsNative.getNativeFont(this.testView);
|
||||
//console.log(`>>>>>>>>>>>>> originalFont: ${fontToString(originalFont)}`);
|
||||
let nativeFont: any;
|
||||
const originalFont = tabViewTestsNative.getOriginalFont(this.testView);
|
||||
TKUnit.assertNotNull(originalFont, "Original Font should be applied");
|
||||
|
||||
//console.log(`>>>>>>>>>>>>> PACIFICO`);
|
||||
this.testView.style.font = "20 Pacifico";
|
||||
nativeFont = tabViewTestsNative.getNativeFont(this.testView);
|
||||
//console.log(`>>>>>>>>>>>>> nativeFont: ${fontToString(nativeFont)}`);
|
||||
let nativeFont = tabViewTestsNative.getNativeFont(this.testView);
|
||||
TKUnit.assertNotNull(nativeFont, "Native Font should not be null");
|
||||
TKUnit.assertNotEqual(originalFont, nativeFont, "Font should be changed");
|
||||
|
||||
//console.log(`>>>>>>>>>>>>> CREATE 3 ITEMS`);
|
||||
this.testView.items = this._createItems(2);
|
||||
assertFontsAreEqual(tabViewTestsNative.getNativeFont(this.testView), nativeFont, "Font must be 20 Pacifico after rebinding items.");
|
||||
//console.log(`>>>>>>>>>>>>> nativeFont: ${fontToString(nativeFont)}`);
|
||||
|
||||
//console.log(`>>>>>>>>>>>>> MONOSPACE;`);
|
||||
this.testView.style.font = "bold 12 monospace";
|
||||
nativeFont = tabViewTestsNative.getNativeFont(this.testView);
|
||||
//console.log(`>>>>>>>>>>>>> nativeFont: ${fontToString(nativeFont)}`);
|
||||
|
||||
//console.log(`>>>>>>>>>>>>> CREATE 3 ITEMS`);
|
||||
this.testView.items = this._createItems(3);
|
||||
assertFontsAreEqual(tabViewTestsNative.getNativeFont(this.testView), nativeFont, "Font must be bold 12 monospace after rebinding items.");
|
||||
//console.log(`>>>>>>>>>>>>> nativeFont: ${fontToString(nativeFont)}`);
|
||||
|
||||
//console.log(`>>>>>>>>>>>>> RESET`);
|
||||
this.testView.style.font = unsetValue;
|
||||
assertFontsAreEqual(tabViewTestsNative.getNativeFont(this.testView), originalFont, "Font must be the original one after resetting the style.");
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ function updateItemTitlePosition(tabBarItem: UITabBarItem): void {
|
||||
}
|
||||
|
||||
function updateItemIconPosition(tabBarItem: UITabBarItem): void {
|
||||
tabBarItem.imageInsets = new UIEdgeInsets({top: 6, left: 0, bottom: -6, right: 0});
|
||||
tabBarItem.imageInsets = new UIEdgeInsets({ top: 6, left: 0, bottom: -6, right: 0 });
|
||||
}
|
||||
|
||||
export class TabViewItem extends TabViewItemBase {
|
||||
@ -130,7 +130,7 @@ export class TabViewItem extends TabViewItemBase {
|
||||
this._iosViewController = controller;
|
||||
this.setNativeView((<any>this)._nativeView = controller.view);
|
||||
}
|
||||
|
||||
|
||||
public disposeNativeView() {
|
||||
this._iosViewController = undefined;
|
||||
this.setNativeView(undefined);
|
||||
@ -462,20 +462,18 @@ function getTitleAttributesForStates(tabView: TabView): TabStates {
|
||||
const result: TabStates = {};
|
||||
|
||||
const font = tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
|
||||
let tabItemTextColor = tabView.style.tabTextColor;
|
||||
if (tabItemTextColor instanceof Color) {
|
||||
result.normalState = {
|
||||
[UITextAttributeTextColor]: tabItemTextColor.ios,
|
||||
[NSFontAttributeName]: font
|
||||
}
|
||||
const tabItemTextColor = tabView.style.tabTextColor;
|
||||
const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
|
||||
result.normalState = { [NSFontAttributeName]: font }
|
||||
if (textColor) {
|
||||
result.normalState[UITextAttributeTextColor] = textColor
|
||||
}
|
||||
|
||||
const tabSelectedItemTextColor = tabView.style.selectedTabTextColor;
|
||||
if (tabSelectedItemTextColor instanceof Color) {
|
||||
result.selectedState = {
|
||||
[UITextAttributeTextColor]: tabSelectedItemTextColor.ios,
|
||||
[NSFontAttributeName]: font
|
||||
}
|
||||
const selectedTextColor = tabItemTextColor instanceof Color ? tabSelectedItemTextColor.ios : null;
|
||||
result.selectedState = { [NSFontAttributeName]: font }
|
||||
if (selectedTextColor) {
|
||||
result.selectedState[UITextAttributeTextColor] = selectedTextColor
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -484,4 +482,4 @@ function getTitleAttributesForStates(tabView: TabView): TabStates {
|
||||
function applyStatesToItem(item: UITabBarItem, states: TabStates) {
|
||||
item.setTitleTextAttributesForState(states.normalState, UIControlState.Normal);
|
||||
item.setTitleTextAttributesForState(states.selectedState, UIControlState.Selected);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user