expo xml font
1.0.0
使用此Expo插件輕鬆使用Android XML字體。
該插件可在https://github.com/jsamr/reaeact-native-font-demo上構建一個很棒的指南,介紹瞭如何在React Native中使用XML字體,但提供了易於使用的API,因此您不必手動使用本機文件。
筆記
V3用於50世紀<= = V2用於Expo 49> =
# using yarn
yarn add expo-xml-font
# using npm
npm install expo-xml-fontapp.json或app.config.js文件的plugins部分: {
"plugins" : [ " expo-xml-font " ]
}此示例將以Inter為例,但您可以使用自己喜歡的任何字體。
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夾中。
在您的app.json或app.config.js中配置expo-xml-font :
{
"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 ;
} [ ] ;
} [ ] ;由於此插件帶有一系列字體,因此您可以根據需要指定任意數量的字體系列。