fix(android): Span should accept all font weight types

This commit is contained in:
Dimitris - Rafail Katsampas
2024-11-30 00:34:37 +02:00
committed by Nathan Walker
parent e545f5869c
commit a21d4f94ac
6 changed files with 94 additions and 45 deletions

View File

@ -1,4 +1,4 @@
import { Font as FontBase, parseFontFamily, FontWeight, FontVariationSettings, fuzzySearch } from './font-common';
import { Font as FontBase, parseFontFamily, FontWeight, FontVariationSettings, fuzzySearch, FONTS_BASE_PATH } from './font-common';
import { FontStyleType, FontWeightType, FontVariationSettingsType } from './font-interfaces';
import { Trace } from '../../trace';
import * as fs from '../../file-system';
@ -115,10 +115,9 @@ export class Font extends FontBase {
}
function getNativeFontWeight(fontWeight: FontWeightType): number {
if (typeof fontWeight === 'number') {
fontWeight = (fontWeight + '') as any;
}
switch (fontWeight) {
const value = typeof fontWeight === 'number' ? fontWeight + '' : fontWeight;
switch (value) {
case FontWeight.THIN:
return UIFontWeightUltraLight;
case FontWeight.EXTRA_LIGHT:
@ -148,7 +147,7 @@ function getNativeFontWeight(fontWeight: FontWeightType): number {
export namespace ios {
export function registerFont(fontFile: string) {
let filePath = fs.path.join(fs.knownFolders.currentApp().path, 'fonts', fontFile);
let filePath = fs.path.join(fs.knownFolders.currentApp().path, FONTS_BASE_PATH, fontFile);
if (!fs.File.exists(filePath)) {
filePath = fs.path.join(fs.knownFolders.currentApp().path, fontFile);
}
@ -179,7 +178,8 @@ function registerFontsInFolder(fontsFolderPath) {
if (fs.Folder.exists(fs.path.join(fontsFolderPath, fileEntity.name))) {
return true;
}
if (fileEntity instanceof fs.File && ((<fs.File>fileEntity).extension === '.ttf' || (<fs.File>fileEntity).extension === '.otf')) {
if (fileEntity instanceof fs.File && (fileEntity.extension === '.ttf' || fileEntity.extension === '.otf')) {
ios.registerFont(fileEntity.name);
}
@ -189,7 +189,7 @@ function registerFontsInFolder(fontsFolderPath) {
function registerCustomFonts() {
const appDir = fs.knownFolders.currentApp().path;
const fontsDir = fs.path.join(appDir, 'fonts');
const fontsDir = fs.path.join(appDir, FONTS_BASE_PATH);
if (fs.Folder.exists(fontsDir)) {
registerFontsInFolder(fontsDir);
}