mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +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 {
|
export function getNativeTabCount(tabView: TabView): number {
|
||||||
var pagerAdapter: android.support.v4.view.PagerAdapter = (<any>tabView)._pagerAdapter;
|
const pagerAdapter: android.support.v4.view.PagerAdapter = (<any>tabView)._pagerAdapter;
|
||||||
return pagerAdapter ? pagerAdapter.getCount() : 0;
|
return pagerAdapter ? pagerAdapter.getCount() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectNativeTab(tabView: tabViewModule.TabView, index: number): void {
|
export function selectNativeTab(tabView: TabView, index: number): void {
|
||||||
var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
|
const viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
|
||||||
if (viewPager) {
|
if (viewPager) {
|
||||||
viewPager.setCurrentItem(index);
|
viewPager.setCurrentItem(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNativeSelectedIndex(tabView: tabViewModule.TabView): number {
|
export function getNativeSelectedIndex(tabView: TabView): number {
|
||||||
var viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
|
const viewPager: android.support.v4.view.ViewPager = (<any>tabView)._viewPager;
|
||||||
return viewPager ? viewPager.getCurrentItem() : -1;
|
return viewPager ? viewPager.getCurrentItem() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNativeFont(tabView: tabViewModule.TabView): any {
|
export function getNativeFont(tabView: TabView): any {
|
||||||
var tv: android.widget.TextView = (<org.nativescript.widgets.TabLayout>(<any>tabView)._tabLayout).getTextViewForItemAt(0);
|
const tv: android.widget.TextView = (<org.nativescript.widgets.TabLayout>(<any>tabView)._tabLayout).getTextViewForItemAt(0);
|
||||||
if (tv) {
|
if (tv) {
|
||||||
return {
|
return {
|
||||||
typeface: tv.getTypeface(),
|
typeface: tv.getTypeface(),
|
||||||
size: tv.getTextSize()
|
size: tv.getTextSize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return null;
|
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
|
//@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 function getNativeTabCount(tabView: TabView): number;
|
||||||
export declare function selectNativeTab(tabView: tabViewModule.TabView, index: number): void;
|
export function selectNativeTab(tabView: TabView, index: number): void;
|
||||||
export declare function getNativeSelectedIndex(tabView: tabViewModule.TabView): number;
|
export function getNativeSelectedIndex(tabView: TabView): number;
|
||||||
export declare function getNativeFont(tabView: tabViewModule.TabView): any;
|
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;
|
return tabView.ios.selectedIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNativeFont(tabView: tabViewModule.TabView): any {
|
export function getNativeFont(tabView: tabViewModule.TabView): UIFont {
|
||||||
let tabBar = <UITabBar>tabView.ios.tabBar;
|
const tabBar = <UITabBar>tabView.ios.tabBar;
|
||||||
let currentFont;
|
|
||||||
|
|
||||||
if (tabBar.items.count > 0) {
|
if (tabBar.items.count > 0) {
|
||||||
let currentAttrs = tabBar.items[0].titleTextAttributesForState(UIControlState.Normal);
|
const currentAttrs = tabBar.items[0].titleTextAttributesForState(UIControlState.Normal);
|
||||||
if (currentAttrs) {
|
if (currentAttrs) {
|
||||||
currentFont = currentAttrs.objectForKey(NSFontAttributeName);
|
return currentAttrs.objectForKey(NSFontAttributeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentFont) {
|
return null;
|
||||||
currentFont = UIFont.systemFontOfSize(getter(UIFont, UIFont.labelFontSize));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentFont;
|
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 () {
|
public test_FontIsReappliedWhenTabItemsChange = function () {
|
||||||
// let fontToString = (font: any): string => {
|
const assertFontsAreEqual = (actual: any, expected: any, message?: string) => {
|
||||||
// if (this.testView.ios){
|
|
||||||
// return font.toString();
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// return `${font.typeface} ${font.size}`;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
let assertFontsAreEqual = (actual: any, expected: any, message?: string) => {
|
|
||||||
if (this.testView.ios) {
|
if (this.testView.ios) {
|
||||||
TKUnit.assertEqual(actual, expected, message);
|
TKUnit.assertEqual(actual, expected, message);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
TKUnit.assertEqual(actual.typeface, expected.typeface, `${message} [typeface]`);
|
TKUnit.assertEqual(actual.typeface, expected.typeface, `${message} [typeface]`);
|
||||||
TKUnit.assertEqual(actual.size, expected.size, `${message} [size]`);
|
TKUnit.assertEqual(actual.size, expected.size, `${message} [size]`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(`>>>>>>>>>>>>> CREATE 3 ITEMS`);
|
|
||||||
this.testView.items = this._createItems(1);
|
this.testView.items = this._createItems(1);
|
||||||
this.waitUntilTestElementIsLoaded();
|
this.waitUntilTestElementIsLoaded();
|
||||||
|
|
||||||
let originalFont = tabViewTestsNative.getNativeFont(this.testView);
|
const originalFont = tabViewTestsNative.getOriginalFont(this.testView);
|
||||||
//console.log(`>>>>>>>>>>>>> originalFont: ${fontToString(originalFont)}`);
|
TKUnit.assertNotNull(originalFont, "Original Font should be applied");
|
||||||
let nativeFont: any;
|
|
||||||
|
|
||||||
//console.log(`>>>>>>>>>>>>> PACIFICO`);
|
|
||||||
this.testView.style.font = "20 Pacifico";
|
this.testView.style.font = "20 Pacifico";
|
||||||
nativeFont = tabViewTestsNative.getNativeFont(this.testView);
|
let nativeFont = tabViewTestsNative.getNativeFont(this.testView);
|
||||||
//console.log(`>>>>>>>>>>>>> nativeFont: ${fontToString(nativeFont)}`);
|
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);
|
this.testView.items = this._createItems(2);
|
||||||
assertFontsAreEqual(tabViewTestsNative.getNativeFont(this.testView), nativeFont, "Font must be 20 Pacifico after rebinding items.");
|
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";
|
this.testView.style.font = "bold 12 monospace";
|
||||||
nativeFont = tabViewTestsNative.getNativeFont(this.testView);
|
nativeFont = tabViewTestsNative.getNativeFont(this.testView);
|
||||||
//console.log(`>>>>>>>>>>>>> nativeFont: ${fontToString(nativeFont)}`);
|
|
||||||
|
|
||||||
//console.log(`>>>>>>>>>>>>> CREATE 3 ITEMS`);
|
|
||||||
this.testView.items = this._createItems(3);
|
this.testView.items = this._createItems(3);
|
||||||
assertFontsAreEqual(tabViewTestsNative.getNativeFont(this.testView), nativeFont, "Font must be bold 12 monospace after rebinding items.");
|
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;
|
this.testView.style.font = unsetValue;
|
||||||
assertFontsAreEqual(tabViewTestsNative.getNativeFont(this.testView), originalFont, "Font must be the original one after resetting the style.");
|
assertFontsAreEqual(tabViewTestsNative.getNativeFont(this.testView), originalFont, "Font must be the original one after resetting the style.");
|
||||||
}
|
}
|
||||||
|
@ -462,20 +462,18 @@ function getTitleAttributesForStates(tabView: TabView): TabStates {
|
|||||||
const result: TabStates = {};
|
const result: TabStates = {};
|
||||||
|
|
||||||
const font = tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
|
const font = tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
|
||||||
let tabItemTextColor = tabView.style.tabTextColor;
|
const tabItemTextColor = tabView.style.tabTextColor;
|
||||||
if (tabItemTextColor instanceof Color) {
|
const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
|
||||||
result.normalState = {
|
result.normalState = { [NSFontAttributeName]: font }
|
||||||
[UITextAttributeTextColor]: tabItemTextColor.ios,
|
if (textColor) {
|
||||||
[NSFontAttributeName]: font
|
result.normalState[UITextAttributeTextColor] = textColor
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabSelectedItemTextColor = tabView.style.selectedTabTextColor;
|
const tabSelectedItemTextColor = tabView.style.selectedTabTextColor;
|
||||||
if (tabSelectedItemTextColor instanceof Color) {
|
const selectedTextColor = tabItemTextColor instanceof Color ? tabSelectedItemTextColor.ios : null;
|
||||||
result.selectedState = {
|
result.selectedState = { [NSFontAttributeName]: font }
|
||||||
[UITextAttributeTextColor]: tabSelectedItemTextColor.ios,
|
if (selectedTextColor) {
|
||||||
[NSFontAttributeName]: font
|
result.selectedState[UITextAttributeTextColor] = selectedTextColor
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user