mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -1154,12 +1154,12 @@ opacityProperty.register(Style);
|
||||
export const colorProperty = new InheritedCssProperty<Style, Color>({ name: "color", cssName: "color", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) });
|
||||
colorProperty.register(Style);
|
||||
|
||||
export const fontInternalProperty = new CssProperty<Style, Font>({ name: "fontInternal", cssName: "_fontInternal", defaultValue: Font.default });
|
||||
export const fontInternalProperty = new CssProperty<Style, Font>({ name: "fontInternal", cssName: "_fontInternal" });
|
||||
fontInternalProperty.register(Style);
|
||||
|
||||
export const fontFamilyProperty = new InheritedCssProperty<Style, string>({
|
||||
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<Style, number>({
|
||||
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<Style, FontStyle>({
|
||||
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<Style, FontWeight>({
|
||||
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;
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user