Используйте Android XML -шрифты с этим плагином Expo.
Этот плагин создает удивительное руководство, доступное по адресу https://github.com/jsamr/react-native-font-demo о том, как использовать шрифты XML в React Native, но обеспечивает прост в использовании API, поэтому вам не нужно вручную ворваться с собственными файлами.
Примечание
v3 для Expo 50 <= Wher V2 для Expo 49> =
# using yarn
yarn add expo-xml-font
# using npm
npm install expo-xml-fontplugins вашего app.json или app.config.js файл: {
"plugins" : [ " expo-xml-font " ]
}В этом примере будет использоваться интерн, но вы можете использовать любой шрифт, который вам нравится.
Inter-Thin.ttf (100)
Inter-ExtraLight.ttf (200)
Inter-Light.ttf (300)
Inter-Regular.ttf (400)
Inter-Medium.ttf (500)
Inter-Semibold.ttf (600)
Inter-Bold.ttf (700)
Inter-Extrabold.ttf (800)
Inter-Black.ttf (900)
inter_thin.ttf (100)
inter_extraLight.ttf (200)
inter_light.ttf (300)
inter_regular.ttf (400)
inter_medium.ttf (500)
inter_semibold.ttf (600)
inter_bold.ttf (700)
inter_extrabold.ttf (800)
inter_black.ttf (900)
Скопируйте эти файлы в папку, где находится ваш проект. Вы можете поместить файлы шрифтов в папку assets/fonts например.
Настройте expo-xml-font в вашем app.json или app.config.js :
{
"plugins" : [
[
" expo-xml-font " ,
[
{
"name" : " Inter " ,
"folder" : " assets/fonts " ,
"variants" : [
{ "fontFile" : " inter_thin " , "fontWeight" : 100 },
{ "fontFile" : " inter_extralight " , "fontWeight" : 200 },
{ "fontFile" : " inter_light " , "fontWeight" : 300 },
{ "fontFile" : " inter_regular " , "fontWeight" : 400 },
{ "fontFile" : " inter_medium " , "fontWeight" : 500 },
{ "fontFile" : " inter_semibold " , "fontWeight" : 600 },
{ "fontFile" : " inter_bold " , "fontWeight" : 700 },
{ "fontFile" : " inter_extrabold " , "fontWeight" : 800 },
{ "fontFile" : " inter_black " , "fontWeight" : 900 }
]
}
]
]
]
}expo prebuild для генерации шрифтов XML. Теперь вы можете использовать их в своем коде! При использовании expo-xml-font вам необходимо пройти в объект, предоставляющий все детали шрифта.
type Options = {
/**
* Name of font
* @example "Inter"
*/
name : string ;
/**
* Path of folder which contains font files. It's alright if the path is relative.
* @example "assets/fonts"
*/
folder : string ;
variants : {
/**
* Font file for font. Do NOT include the extension.
* @example "inter_regular.ttf" -> "inter_regular"
*/
fontFile : string ;
/** The font weight of the provided font file */
fontWeight : 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 ;
/**
* Specifies whether or not the font file is italic
* @default false
*/
italic ?: boolean ;
} [ ] ;
} [ ] ;Поскольку этот плагин принимает множество шрифтов, вы можете указать столько семей шрифтов, сколько хотите.