mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
fix(core): font-weight allow passing number (#10072)
This commit is contained in:
@ -27,8 +27,8 @@ export abstract class Font implements FontDefinition {
|
||||
public abstract getAndroidTypeface(): any; /* android.graphics.Typeface */
|
||||
public abstract getUIFont(defaultFont: any /* UIFont */): any; /* UIFont */
|
||||
public abstract withFontFamily(family: string): Font;
|
||||
public abstract withFontStyle(style: string): Font;
|
||||
public abstract withFontWeight(weight: string): Font;
|
||||
public abstract withFontStyle(style: FontStyleType): Font;
|
||||
public abstract withFontWeight(weight: FontWeightType): Font;
|
||||
public abstract withFontSize(size: number): Font;
|
||||
public abstract withFontScale(scale: number): Font;
|
||||
|
||||
@ -55,7 +55,7 @@ export namespace FontStyle {
|
||||
export const parse = makeParser<FontStyleType>(isValid);
|
||||
}
|
||||
|
||||
export type FontWeightType = '100' | '200' | '300' | 'normal' | '400' | '500' | '600' | 'bold' | '700' | '800' | '900';
|
||||
export type FontWeightType = '100' | '200' | '300' | 'normal' | '400' | '500' | '600' | 'bold' | '700' | '800' | '900' | number;
|
||||
export namespace FontWeight {
|
||||
export const THIN = '100';
|
||||
export const EXTRA_LIGHT = '200';
|
||||
|
@ -1,6 +1,6 @@
|
||||
export type FontStyle = 'normal' | 'italic';
|
||||
|
||||
export type FontWeight = '100' | '200' | '300' | 'normal' | '400' | '500' | '600' | 'bold' | '700' | '800' | '900';
|
||||
export type FontWeight = '100' | '200' | '300' | 'normal' | '400' | '500' | '600' | 'bold' | '700' | '800' | '900' | number;
|
||||
|
||||
export interface ParsedFont {
|
||||
fontStyle?: FontStyle;
|
||||
|
@ -139,6 +139,9 @@ function createTypeface(font: Font): android.graphics.Typeface {
|
||||
}
|
||||
|
||||
function getFontWeightSuffix(fontWeight: FontWeightType): string {
|
||||
if (typeof fontWeight === 'number') {
|
||||
fontWeight = (fontWeight + '') as any;
|
||||
}
|
||||
switch (fontWeight) {
|
||||
case FontWeight.THIN:
|
||||
return android.os.Build.VERSION.SDK_INT >= 16 ? '-thin' : '';
|
||||
|
6
packages/core/ui/styling/font.d.ts
vendored
6
packages/core/ui/styling/font.d.ts
vendored
@ -16,8 +16,8 @@
|
||||
public getUIFont(defaultFont: any /* UIFont */): any /* UIFont */;
|
||||
|
||||
public withFontFamily(family: string): Font;
|
||||
public withFontStyle(style: string): Font;
|
||||
public withFontWeight(weight: string): Font;
|
||||
public withFontStyle(style: FontStyle): Font;
|
||||
public withFontWeight(weight: FontWeight): Font;
|
||||
public withFontSize(size: number): Font;
|
||||
public withFontScale(scale: number): Font;
|
||||
|
||||
@ -32,7 +32,7 @@ export namespace FontStyle {
|
||||
export function parse(value: string): FontStyle;
|
||||
}
|
||||
|
||||
export type FontWeight = '100' | '200' | '300' | 'normal' | '400' | '500' | '600' | 'bold' | '700' | '800' | '900';
|
||||
export type FontWeight = '100' | '200' | '300' | 'normal' | '400' | '500' | '600' | 'bold' | '700' | '800' | '900' | number;
|
||||
export namespace FontWeight {
|
||||
export const THIN: '100';
|
||||
export const EXTRA_LIGHT: '200';
|
||||
|
@ -80,6 +80,9 @@ export class Font extends FontBase {
|
||||
}
|
||||
|
||||
function getNativeFontWeight(fontWeight: FontWeightType): number {
|
||||
if (typeof fontWeight === 'number') {
|
||||
fontWeight = (fontWeight + '') as any;
|
||||
}
|
||||
switch (fontWeight) {
|
||||
case FontWeight.THIN:
|
||||
return UIFontWeightUltraLight;
|
||||
|
Reference in New Issue
Block a user