mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 02:54:11 +08:00
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:
@ -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';
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
2
packages/core/ui/styling/font.d.ts
vendored
2
packages/core/ui/styling/font.d.ts
vendored
@ -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 */;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user