Skip to content

Commit ad9daa8

Browse files
fix: dont default to Font.default (#8401)
* fix: dont default to Font.default This would cause a font to be set for any label even when using default system font. This will also cause a typeface which is pretty long * lint: lint fixes * fix: added null font guards * fix: Used default bold for TabView Co-authored-by: Vasko <v.trifonov@gmail.com>
1 parent 56f6626 commit ad9daa8

12 files changed

Lines changed: 32 additions & 26 deletions

File tree

nativescript-core/image-source/image-source.android.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export class ImageSource implements ImageSourceDefinition {
176176
}
177177

178178
static fromFontIconCodeSync(source: string, font: Font, color: Color): ImageSource {
179+
font = font || Font.default;
179180
const paint = new android.graphics.Paint();
180181
paint.setTypeface(font.getAndroidTypeface());
181182
paint.setAntiAlias(true);

nativescript-core/image-source/image-source.ios.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export class ImageSource implements ImageSourceDefinition {
165165
}
166166

167167
static fromFontIconCodeSync(source: string, font: Font, color: Color): ImageSource {
168+
font = font || Font.default;
168169
let fontSize = layout.toDevicePixels(font.fontSize);
169170
if (!fontSize) {
170171
// TODO: Consider making 36 font size as default for optimal look on TabView and ActionBar

nativescript-core/ui/bottom-navigation/bottom-navigation.ios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ export class BottomNavigation extends TabNavigationBase {
654654
}
655655

656656
const target = tabStripItem.image;
657-
const font = target.style.fontInternal;
657+
const font = target.style.fontInternal || Font.default;
658658
if (!color) {
659659
color = target.style.color;
660660
}
@@ -774,7 +774,7 @@ export class BottomNavigation extends TabNavigationBase {
774774

775775
const defaultTabItemFontSize = 10;
776776
const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize;
777-
const font: UIFont = view.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
777+
const font: UIFont = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
778778
const tabItemTextColor = view.style.color;
779779
const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
780780
let attributes: any = { [NSFontAttributeName]: font };

nativescript-core/ui/styling/style-properties.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,12 +1154,12 @@ opacityProperty.register(Style);
11541154
export const colorProperty = new InheritedCssProperty<Style, Color>({ name: "color", cssName: "color", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) });
11551155
colorProperty.register(Style);
11561156

1157-
export const fontInternalProperty = new CssProperty<Style, Font>({ name: "fontInternal", cssName: "_fontInternal", defaultValue: Font.default });
1157+
export const fontInternalProperty = new CssProperty<Style, Font>({ name: "fontInternal", cssName: "_fontInternal" });
11581158
fontInternalProperty.register(Style);
11591159

11601160
export const fontFamilyProperty = new InheritedCssProperty<Style, string>({
11611161
name: "fontFamily", cssName: "font-family", affectsLayout: isIOS, valueChanged: (target, oldValue, newValue) => {
1162-
let currentFont = target.fontInternal;
1162+
let currentFont = target.fontInternal || Font.default;
11631163
if (currentFont.fontFamily !== newValue) {
11641164
const newFont = currentFont.withFontFamily(newValue);
11651165
target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont;
@@ -1170,7 +1170,10 @@ fontFamilyProperty.register(Style);
11701170

11711171
export const fontSizeProperty = new InheritedCssProperty<Style, number>({
11721172
name: "fontSize", cssName: "font-size", affectsLayout: isIOS, valueChanged: (target, oldValue, newValue) => {
1173-
let currentFont = target.fontInternal;
1173+
if (target.viewRef["handleFontSize"] === true) {
1174+
return;
1175+
}
1176+
let currentFont = target.fontInternal || Font.default;
11741177
if (currentFont.fontSize !== newValue) {
11751178
const newFont = currentFont.withFontSize(newValue);
11761179
target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont;
@@ -1182,7 +1185,7 @@ fontSizeProperty.register(Style);
11821185

11831186
export const fontStyleProperty = new InheritedCssProperty<Style, FontStyle>({
11841187
name: "fontStyle", cssName: "font-style", affectsLayout: isIOS, defaultValue: FontStyle.NORMAL, valueConverter: FontStyle.parse, valueChanged: (target, oldValue, newValue) => {
1185-
let currentFont = target.fontInternal;
1188+
let currentFont = target.fontInternal || Font.default;
11861189
if (currentFont.fontStyle !== newValue) {
11871190
const newFont = currentFont.withFontStyle(newValue);
11881191
target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont;
@@ -1193,7 +1196,7 @@ fontStyleProperty.register(Style);
11931196

11941197
export const fontWeightProperty = new InheritedCssProperty<Style, FontWeight>({
11951198
name: "fontWeight", cssName: "font-weight", affectsLayout: isIOS, defaultValue: FontWeight.NORMAL, valueConverter: FontWeight.parse, valueChanged: (target, oldValue, newValue) => {
1196-
let currentFont = target.fontInternal;
1199+
let currentFont = target.fontInternal || Font.default;
11971200
if (currentFont.fontWeight !== newValue) {
11981201
const newFont = currentFont.withFontWeight(newValue);
11991202
target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont;

nativescript-core/ui/tab-view/tab-view.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ function getTitleAttributesForStates(tabView: TabView): TabStates {
587587

588588
const defaultTabItemFontSize = 10;
589589
const tabItemFontSize = tabView.style.tabTextFontSize || defaultTabItemFontSize;
590-
const font: UIFont = tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
590+
const font: UIFont = (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
591591
const tabItemTextColor = tabView.style.tabTextColor;
592592
const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
593593
result.normalState = { [NSFontAttributeName]: font };

nativescript-core/ui/tabs/tabs.ios.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ export class Tabs extends TabsBase {
824824
}
825825

826826
const target = tabStripItem.image;
827-
const font = target.style.fontInternal;
827+
const font = target.style.fontInternal || Font.default;
828828
if (!color) {
829829
color = target.style.color;
830830
}
@@ -997,7 +997,7 @@ export class Tabs extends TabsBase {
997997
public setTabBarFontInternal(value: Font): void {
998998
const defaultTabItemFontSize = 10;
999999
const tabItemFontSize = this.tabStrip.style.fontSize || defaultTabItemFontSize;
1000-
const font: UIFont = this.tabStrip.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
1000+
const font: UIFont = (this.tabStrip.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
10011001

10021002
this._ios.tabBar.unselectedItemTitleFont = font;
10031003
this._ios.tabBar.selectedItemTitleFont = font;
@@ -1194,7 +1194,7 @@ export class Tabs extends TabsBase {
11941194

11951195
const defaultTabItemFontSize = 10;
11961196
const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize;
1197-
const font: UIFont = view.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
1197+
const font: UIFont = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
11981198

11991199
this.viewController.tabBar.unselectedItemTitleFont = font;
12001200
this.viewController.tabBar.selectedItemTitleFont = font;

tests/app/ui/bottom-navigation/bottom-navigation-tests-native.ios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import tabViewModule = require("@nativescript/core/ui/tab-view");
2+
import { Font } from "@nativescript/core/ui/styling/font";
23

34
export function getNativeTabCount(tabView: tabViewModule.TabView): number {
45
if (!tabView.ios.viewControllers) {
@@ -30,5 +31,5 @@ export function getNativeFont(tabView: tabViewModule.TabView): UIFont {
3031
}
3132

3233
export function getOriginalFont(tabView: tabViewModule.TabView): UIFont {
33-
return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
34+
return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10));
3435
}

tests/app/ui/tab-view/tab-view-tests-native.ios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import tabViewModule = require("@nativescript/core/ui/tab-view");
2+
import { Font } from "@nativescript/core/ui/styling/font";
23

34
export function getNativeTabCount(tabView: tabViewModule.TabView): number {
45
if (!tabView.ios.viewControllers) {
@@ -30,5 +31,5 @@ export function getNativeFont(tabView: tabViewModule.TabView): UIFont {
3031
}
3132

3233
export function getOriginalFont(tabView: tabViewModule.TabView): UIFont {
33-
return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
34+
return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10));
3435
}

tests/app/ui/tabs/tabs-tests-native.ios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Tabs } from "@nativescript/core/ui/tabs";
2+
import { Font } from "@nativescript/core/ui/styling/font";
23

34
// TODO: Should we add getCount to UIPageViewController???
45
export function getNativeTabCount(tabView: Tabs): number {
@@ -39,5 +40,5 @@ export function getNativeFont(tabView: Tabs): UIFont {
3940
}
4041

4142
export function getOriginalFont(tabView: Tabs): UIFont {
42-
return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
43+
return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10));
4344
}

tns-core-modules-widgets/android/widgets/src/main/java/org/nativescript/widgets/BottomNavigationBar.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ protected View createDefaultTabView(Context context, TabItemSpec tabItem) {
178178
titleTextView.setGravity(Gravity.CENTER);
179179
titleTextView.setMaxWidth((int) (ITEM_TEXT_MAX_WIDTH * density));
180180
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, ITEM_TEXT_SIZE_SP);
181-
titleTextView.setTypeface(Typeface.DEFAULT_BOLD);
182181
titleTextView.setEllipsize(TextUtils.TruncateAt.END);
183182
titleTextView.setMaxLines(1);
184183
titleTextView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

0 commit comments

Comments
 (0)