diff --git a/tests/app/ui/tab-view/tab-view-tests-native.android.ts b/tests/app/ui/tab-view/tab-view-tests-native.android.ts index 56b2c2ab3..4c89d5bad 100644 --- a/tests/app/ui/tab-view/tab-view-tests-native.android.ts +++ b/tests/app/ui/tab-view/tab-view-tests-native.android.ts @@ -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 = (tabView)._pagerAdapter; +export function getNativeTabCount(tabView: TabView): number { + const pagerAdapter: android.support.v4.view.PagerAdapter = (tabView)._pagerAdapter; return pagerAdapter ? pagerAdapter.getCount() : 0; } -export function selectNativeTab(tabView: tabViewModule.TabView, index: number): void { - var viewPager: android.support.v4.view.ViewPager = (tabView)._viewPager; +export function selectNativeTab(tabView: TabView, index: number): void { + const viewPager: android.support.v4.view.ViewPager = (tabView)._viewPager; if (viewPager) { viewPager.setCurrentItem(index); } } -export function getNativeSelectedIndex(tabView: tabViewModule.TabView): number { - var viewPager: android.support.v4.view.ViewPager = (tabView)._viewPager; +export function getNativeSelectedIndex(tabView: TabView): number { + const viewPager: android.support.v4.view.ViewPager = (tabView)._viewPager; return viewPager ? viewPager.getCurrentItem() : -1; } -export function getNativeFont(tabView: tabViewModule.TabView): any { - var tv: android.widget.TextView = ((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 = ((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 = ((tabView)._tabLayout).getTextViewForItemAt(0); + return { + typeface: tv.getTypeface(), + size: tv.getTextSize() + } +} \ No newline at end of file diff --git a/tests/app/ui/tab-view/tab-view-tests-native.d.ts b/tests/app/ui/tab-view/tab-view-tests-native.d.ts index 453fcafb4..26984255a 100644 --- a/tests/app/ui/tab-view/tab-view-tests-native.d.ts +++ b/tests/app/ui/tab-view/tab-view-tests-native.d.ts @@ -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; \ No newline at end of file diff --git a/tests/app/ui/tab-view/tab-view-tests-native.ios.ts b/tests/app/ui/tab-view/tab-view-tests-native.ios.ts index 23620e13b..47cea99ca 100644 --- a/tests/app/ui/tab-view/tab-view-tests-native.ios.ts +++ b/tests/app/ui/tab-view/tab-view-tests-native.ios.ts @@ -19,20 +19,18 @@ export function getNativeSelectedIndex(tabView: tabViewModule.TabView): number { return tabView.ios.selectedIndex; } -export function getNativeFont(tabView: tabViewModule.TabView): any { - let tabBar = tabView.ios.tabBar; - let currentFont; - +export function getNativeFont(tabView: tabViewModule.TabView): UIFont { + const tabBar = 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)); +} \ No newline at end of file diff --git a/tests/app/ui/tab-view/tab-view-tests.ts b/tests/app/ui/tab-view/tab-view-tests.ts index d2ff3bf22..9f58157d4 100644 --- a/tests/app/ui/tab-view/tab-view-tests.ts +++ b/tests/app/ui/tab-view/tab-view-tests.ts @@ -290,54 +290,35 @@ export class TabViewTest extends testModule.UITest { } 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."); } diff --git a/tns-core-modules/ui/tab-view/tab-view.ios.ts b/tns-core-modules/ui/tab-view/tab-view.ios.ts index 1c2a431fd..7bf05348a 100644 --- a/tns-core-modules/ui/tab-view/tab-view.ios.ts +++ b/tns-core-modules/ui/tab-view/tab-view.ios.ts @@ -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((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); -} +} \ No newline at end of file