diff --git a/nativescript-core/image-source/image-source.android.ts b/nativescript-core/image-source/image-source.android.ts index 17479ad10..18a0fd76e 100644 --- a/nativescript-core/image-source/image-source.android.ts +++ b/nativescript-core/image-source/image-source.android.ts @@ -176,6 +176,7 @@ export class ImageSource implements ImageSourceDefinition { } static fromFontIconCodeSync(source: string, font: Font, color: Color): ImageSource { + font = font || Font.default; const paint = new android.graphics.Paint(); paint.setTypeface(font.getAndroidTypeface()); paint.setAntiAlias(true); diff --git a/nativescript-core/image-source/image-source.ios.ts b/nativescript-core/image-source/image-source.ios.ts index c020bd0fe..c0d007a1a 100644 --- a/nativescript-core/image-source/image-source.ios.ts +++ b/nativescript-core/image-source/image-source.ios.ts @@ -165,6 +165,7 @@ export class ImageSource implements ImageSourceDefinition { } static fromFontIconCodeSync(source: string, font: Font, color: Color): ImageSource { + font = font || Font.default; let fontSize = layout.toDevicePixels(font.fontSize); if (!fontSize) { // TODO: Consider making 36 font size as default for optimal look on TabView and ActionBar diff --git a/nativescript-core/ui/bottom-navigation/bottom-navigation.ios.ts b/nativescript-core/ui/bottom-navigation/bottom-navigation.ios.ts index e57f718d7..73fc214b2 100644 --- a/nativescript-core/ui/bottom-navigation/bottom-navigation.ios.ts +++ b/nativescript-core/ui/bottom-navigation/bottom-navigation.ios.ts @@ -654,7 +654,7 @@ export class BottomNavigation extends TabNavigationBase { } const target = tabStripItem.image; - const font = target.style.fontInternal; + const font = target.style.fontInternal || Font.default; if (!color) { color = target.style.color; } @@ -774,7 +774,7 @@ export class BottomNavigation extends TabNavigationBase { const defaultTabItemFontSize = 10; const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize; - const font: UIFont = view.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize)); + const font: UIFont = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize)); const tabItemTextColor = view.style.color; const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null; let attributes: any = { [NSFontAttributeName]: font }; diff --git a/nativescript-core/ui/styling/style-properties.ts b/nativescript-core/ui/styling/style-properties.ts index 8ee732be0..c2628fa2a 100644 --- a/nativescript-core/ui/styling/style-properties.ts +++ b/nativescript-core/ui/styling/style-properties.ts @@ -1154,12 +1154,12 @@ opacityProperty.register(Style); export const colorProperty = new InheritedCssProperty({ name: "color", cssName: "color", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) }); colorProperty.register(Style); -export const fontInternalProperty = new CssProperty({ name: "fontInternal", cssName: "_fontInternal", defaultValue: Font.default }); +export const fontInternalProperty = new CssProperty({ name: "fontInternal", cssName: "_fontInternal" }); fontInternalProperty.register(Style); export const fontFamilyProperty = new InheritedCssProperty({ name: "fontFamily", cssName: "font-family", affectsLayout: isIOS, valueChanged: (target, oldValue, newValue) => { - let currentFont = target.fontInternal; + let currentFont = target.fontInternal || Font.default; if (currentFont.fontFamily !== newValue) { const newFont = currentFont.withFontFamily(newValue); target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont; @@ -1170,7 +1170,10 @@ fontFamilyProperty.register(Style); export const fontSizeProperty = new InheritedCssProperty({ name: "fontSize", cssName: "font-size", affectsLayout: isIOS, valueChanged: (target, oldValue, newValue) => { - let currentFont = target.fontInternal; + if (target.viewRef["handleFontSize"] === true) { + return; + } + let currentFont = target.fontInternal || Font.default; if (currentFont.fontSize !== newValue) { const newFont = currentFont.withFontSize(newValue); target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont; @@ -1182,7 +1185,7 @@ fontSizeProperty.register(Style); export const fontStyleProperty = new InheritedCssProperty({ name: "fontStyle", cssName: "font-style", affectsLayout: isIOS, defaultValue: FontStyle.NORMAL, valueConverter: FontStyle.parse, valueChanged: (target, oldValue, newValue) => { - let currentFont = target.fontInternal; + let currentFont = target.fontInternal || Font.default; if (currentFont.fontStyle !== newValue) { const newFont = currentFont.withFontStyle(newValue); target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont; @@ -1193,7 +1196,7 @@ fontStyleProperty.register(Style); export const fontWeightProperty = new InheritedCssProperty({ name: "fontWeight", cssName: "font-weight", affectsLayout: isIOS, defaultValue: FontWeight.NORMAL, valueConverter: FontWeight.parse, valueChanged: (target, oldValue, newValue) => { - let currentFont = target.fontInternal; + let currentFont = target.fontInternal || Font.default; if (currentFont.fontWeight !== newValue) { const newFont = currentFont.withFontWeight(newValue); target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont; diff --git a/nativescript-core/ui/tab-view/tab-view.ios.ts b/nativescript-core/ui/tab-view/tab-view.ios.ts index ec96eaaab..d6d61211d 100644 --- a/nativescript-core/ui/tab-view/tab-view.ios.ts +++ b/nativescript-core/ui/tab-view/tab-view.ios.ts @@ -587,7 +587,7 @@ function getTitleAttributesForStates(tabView: TabView): TabStates { const defaultTabItemFontSize = 10; const tabItemFontSize = tabView.style.tabTextFontSize || defaultTabItemFontSize; - const font: UIFont = tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize)); + const font: UIFont = (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize)); const tabItemTextColor = tabView.style.tabTextColor; const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null; result.normalState = { [NSFontAttributeName]: font }; diff --git a/nativescript-core/ui/tabs/tabs.ios.ts b/nativescript-core/ui/tabs/tabs.ios.ts index 15c81af55..e22132fa7 100644 --- a/nativescript-core/ui/tabs/tabs.ios.ts +++ b/nativescript-core/ui/tabs/tabs.ios.ts @@ -824,7 +824,7 @@ export class Tabs extends TabsBase { } const target = tabStripItem.image; - const font = target.style.fontInternal; + const font = target.style.fontInternal || Font.default; if (!color) { color = target.style.color; } @@ -997,7 +997,7 @@ export class Tabs extends TabsBase { public setTabBarFontInternal(value: Font): void { const defaultTabItemFontSize = 10; const tabItemFontSize = this.tabStrip.style.fontSize || defaultTabItemFontSize; - const font: UIFont = this.tabStrip.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize)); + const font: UIFont = (this.tabStrip.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize)); this._ios.tabBar.unselectedItemTitleFont = font; this._ios.tabBar.selectedItemTitleFont = font; @@ -1194,7 +1194,7 @@ export class Tabs extends TabsBase { const defaultTabItemFontSize = 10; const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize; - const font: UIFont = view.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize)); + const font: UIFont = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize)); this.viewController.tabBar.unselectedItemTitleFont = font; this.viewController.tabBar.selectedItemTitleFont = font; diff --git a/tests/app/ui/bottom-navigation/bottom-navigation-tests-native.ios.ts b/tests/app/ui/bottom-navigation/bottom-navigation-tests-native.ios.ts index c7a3548a9..f1caa18fd 100644 --- a/tests/app/ui/bottom-navigation/bottom-navigation-tests-native.ios.ts +++ b/tests/app/ui/bottom-navigation/bottom-navigation-tests-native.ios.ts @@ -1,4 +1,5 @@ import tabViewModule = require("@nativescript/core/ui/tab-view"); +import { Font } from "@nativescript/core/ui/styling/font"; export function getNativeTabCount(tabView: tabViewModule.TabView): number { if (!tabView.ios.viewControllers) { @@ -30,5 +31,5 @@ export function getNativeFont(tabView: tabViewModule.TabView): UIFont { } export function getOriginalFont(tabView: tabViewModule.TabView): UIFont { - return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10)); + return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10)); } 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 c7a3548a9..f1caa18fd 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 @@ -1,4 +1,5 @@ import tabViewModule = require("@nativescript/core/ui/tab-view"); +import { Font } from "@nativescript/core/ui/styling/font"; export function getNativeTabCount(tabView: tabViewModule.TabView): number { if (!tabView.ios.viewControllers) { @@ -30,5 +31,5 @@ export function getNativeFont(tabView: tabViewModule.TabView): UIFont { } export function getOriginalFont(tabView: tabViewModule.TabView): UIFont { - return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10)); + return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10)); } diff --git a/tests/app/ui/tabs/tabs-tests-native.ios.ts b/tests/app/ui/tabs/tabs-tests-native.ios.ts index e55b8307d..f33e6e779 100644 --- a/tests/app/ui/tabs/tabs-tests-native.ios.ts +++ b/tests/app/ui/tabs/tabs-tests-native.ios.ts @@ -1,4 +1,5 @@ import { Tabs } from "@nativescript/core/ui/tabs"; +import { Font } from "@nativescript/core/ui/styling/font"; // TODO: Should we add getCount to UIPageViewController??? export function getNativeTabCount(tabView: Tabs): number { @@ -39,5 +40,5 @@ export function getNativeFont(tabView: Tabs): UIFont { } export function getOriginalFont(tabView: Tabs): UIFont { - return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10)); + return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10)); } diff --git a/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/BottomNavigationBar.java b/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/BottomNavigationBar.java index 13760a683..98ab8834e 100644 --- a/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/BottomNavigationBar.java +++ b/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/BottomNavigationBar.java @@ -178,7 +178,6 @@ public class BottomNavigationBar extends LinearLayout { titleTextView.setGravity(Gravity.CENTER); titleTextView.setMaxWidth((int) (ITEM_TEXT_MAX_WIDTH * density)); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, ITEM_TEXT_SIZE_SP); - titleTextView.setTypeface(Typeface.DEFAULT_BOLD); titleTextView.setEllipsize(TextUtils.TruncateAt.END); titleTextView.setMaxLines(1); titleTextView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); diff --git a/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabLayout.java b/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabLayout.java index a784d5431..32337a760 100644 --- a/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabLayout.java +++ b/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabLayout.java @@ -160,7 +160,7 @@ public class TabLayout extends HorizontalScrollView { * {@link TabLayout} you are required to set any * {@link ViewPager.OnPageChangeListener} through this method. This is so * that the layout can update it's scroll position correctly. - * + * * @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener) */ public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) { @@ -196,25 +196,25 @@ public class TabLayout extends HorizontalScrollView { TextView textView = (TextView)ll.getChildAt(1); this.setupItem(ll, textView, imgView, tabItem); } - + /** * Gets the TextView for tab item at index */ public TextView getTextViewForItemAt(int index){ LinearLayout ll = this.getViewForItemAt(index); - return (ll != null) ? (TextView)ll.getChildAt(1) : null; + return (ll != null) ? (TextView)ll.getChildAt(1) : null; } - + /** * Gets the LinearLayout container for tab item at index */ public LinearLayout getViewForItemAt(int index){ LinearLayout result = null; - + if(this.mTabStrip.getChildCount() > index){ result = (LinearLayout)this.mTabStrip.getChildAt(index); } - + return result; } @@ -263,10 +263,10 @@ public class TabLayout extends HorizontalScrollView { ll.addView(textView); return ll; } - + private void setupItem(LinearLayout ll, TextView textView,ImageView imgView, TabItemSpec tabItem){ float density = getResources().getDisplayMetrics().density; - + if (tabItem.iconId != 0) { imgView.setImageResource(tabItem.iconId); imgView.setVisibility(VISIBLE); @@ -293,7 +293,7 @@ public class TabLayout extends HorizontalScrollView { } else { ll.setMinimumHeight((int) (SMALL_MIN_HEIGHT * density)); } - + if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams(); lp.width = 0; @@ -438,4 +438,4 @@ public class TabLayout extends HorizontalScrollView { } } } -} \ No newline at end of file +} diff --git a/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabsBar.java b/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabsBar.java index b34137ba4..3f9e53dbe 100644 --- a/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabsBar.java +++ b/tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/TabsBar.java @@ -250,7 +250,6 @@ public class TabsBar extends HorizontalScrollView { textView.setGravity(Gravity.CENTER); textView.setMaxWidth((int) (TEXT_MAX_WIDTH * density)); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); - textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setMaxLines(2); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));