feat(core): make font style, weight, scale params optional (#9993)

Change font style, weight, scale constructor parameters to optional.
Export `FontStyle` and `FontWeight`.
This commit is contained in:
Ruslan Lekhman
2022-08-12 19:41:57 -06:00
committed by GitHub
parent 64c2dd8c72
commit 4b0c812707
5 changed files with 16 additions and 11 deletions

View File

@ -59,7 +59,7 @@ export { Background } from './styling/background';
export type { CacheMode } from './styling/background';
export { parseCSSShadow } from './styling/css-shadow';
export { animationTimingFunctionConverter, timeConverter } from './styling/converters';
export { Font } from './styling/font';
export { Font, FontStyle, FontWeight } from './styling/font';
export { Style } from './styling/style';
export type { CommonLayoutParams } from './styling/style';
export * from './styling/style-properties';

View File

@ -6,6 +6,9 @@ export * from './font-interfaces';
export abstract class Font implements FontDefinition {
public static default = undefined;
public readonly fontStyle: FontStyleType;
public readonly fontWeight: FontWeightType;
public readonly fontScale: number;
get isItalic(): boolean {
return this.fontStyle === FontStyle.ITALIC;
@ -15,7 +18,11 @@ export abstract class Font implements FontDefinition {
return this.fontWeight === FontWeight.SEMI_BOLD || this.fontWeight === FontWeight.BOLD || this.fontWeight === '700' || this.fontWeight === FontWeight.EXTRA_BOLD || this.fontWeight === FontWeight.BLACK;
}
protected constructor(public readonly fontFamily: string, public readonly fontSize: number, public readonly fontStyle: FontStyleType, public readonly fontWeight: FontWeightType, public readonly fontScale: number) {}
protected constructor(public readonly fontFamily: string, public readonly fontSize: number, fontStyle?: FontStyleType, fontWeight?: FontWeightType, fontScale?: number) {
this.fontStyle = fontStyle ?? FontStyle.NORMAL;
this.fontWeight = fontWeight ?? FontWeight.NORMAL;
this.fontScale = fontScale ?? 1;
}
public abstract getAndroidTypeface(): any; /* android.graphics.Typeface */
public abstract getUIFont(defaultFont: any /* UIFont */): any; /* UIFont */

View File

@ -1,4 +1,4 @@
import { Font as FontBase, parseFontFamily, genericFontFamilies, FontWeight, FontWeightType } from './font-common';
import { Font as FontBase, parseFontFamily, genericFontFamilies, FontStyleType, FontWeight, FontWeightType } from './font-common';
import { Trace } from '../../trace';
import * as application from '../../application';
import * as fs from '../../file-system';
@ -10,11 +10,11 @@ const typefaceCache = new Map<string, android.graphics.Typeface>();
let appAssets: android.content.res.AssetManager;
export class Font extends FontBase {
public static default = new Font(undefined, undefined, 'normal', 'normal');
public static default = new Font(undefined, undefined);
private _typeface: android.graphics.Typeface;
constructor(family: string, size: number, style: 'normal' | 'italic', weight: FontWeightType) {
constructor(family: string, size: number, style?: FontStyleType, weight?: FontWeightType) {
super(family, size, style, weight, 1);
}
@ -22,7 +22,7 @@ export class Font extends FontBase {
return new Font(family, this.fontSize, this.fontStyle, this.fontWeight);
}
public withFontStyle(style: 'normal' | 'italic'): Font {
public withFontStyle(style: FontStyleType): Font {
return new Font(this.fontFamily, this.fontSize, style, this.fontWeight);
}

View File

@ -10,7 +10,7 @@
public isBold: boolean;
public isItalic: boolean;
constructor(family: string, size: number, style: FontStyle, weight: FontWeight);
constructor(family: string, size: number, style?: FontStyle, weight?: FontWeight, scale?: number);
public getAndroidTypeface(): any /* android.graphics.Typeface */;
public getUIFont(defaultFont: any /* UIFont */): any /* UIFont */;

View File

@ -38,11 +38,9 @@ function getUIFontCached(fontDescriptor: FontDescriptor) {
}
export class Font extends FontBase {
public static default = new Font(undefined, undefined, FontStyle.NORMAL, FontWeight.NORMAL, 1);
public static default = new Font(undefined, undefined);
private _uiFont: UIFont;
constructor(family: string, size: number, style: FontStyleType, weight: FontWeightType, scale: number) {
constructor(family: string, size: number, style?: FontStyleType, weight?: FontWeightType, scale?: number) {
super(family, size, style, weight, scale);
}