From 5f3f1ace280d7da302977ccb10d2525a48b65cf1 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Mon, 7 Nov 2022 21:52:13 +0000 Subject: [PATCH] fix(core): font-weight allow passing number (#10072) --- packages/core/ui/styling/font-common.ts | 6 +++--- packages/core/ui/styling/font-interfaces.ts | 2 +- packages/core/ui/styling/font.android.ts | 3 +++ packages/core/ui/styling/font.d.ts | 6 +++--- packages/core/ui/styling/font.ios.ts | 3 +++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/core/ui/styling/font-common.ts b/packages/core/ui/styling/font-common.ts index 9d10e275c..b5f6c53ff 100644 --- a/packages/core/ui/styling/font-common.ts +++ b/packages/core/ui/styling/font-common.ts @@ -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(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'; diff --git a/packages/core/ui/styling/font-interfaces.ts b/packages/core/ui/styling/font-interfaces.ts index 1065d1f60..948f26822 100644 --- a/packages/core/ui/styling/font-interfaces.ts +++ b/packages/core/ui/styling/font-interfaces.ts @@ -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; diff --git a/packages/core/ui/styling/font.android.ts b/packages/core/ui/styling/font.android.ts index c10d4ec8c..944e37661 100644 --- a/packages/core/ui/styling/font.android.ts +++ b/packages/core/ui/styling/font.android.ts @@ -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' : ''; diff --git a/packages/core/ui/styling/font.d.ts b/packages/core/ui/styling/font.d.ts index 4d6650e6b..f67607759 100644 --- a/packages/core/ui/styling/font.d.ts +++ b/packages/core/ui/styling/font.d.ts @@ -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'; diff --git a/packages/core/ui/styling/font.ios.ts b/packages/core/ui/styling/font.ios.ts index b8e163bfd..d1d70c8e9 100644 --- a/packages/core/ui/styling/font.ios.ts +++ b/packages/core/ui/styling/font.ios.ts @@ -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;