简体   繁体   English

React Native 自定义字体适用于 IOS 但不适用于 Android

[英]React Native custom fonts working on IOS but not on Android

I've added the Google Font Fira Sans fonts (Italic, Bold, Regular), following the react-native link procedure.我已经按照react-native link程序添加了 Google Font Fira Sans 字体(斜体、粗体、常规)。

I can see the fonts have been copied to src/main/assets/fonts , likewise in Resources folder for IOS我可以看到字体已被复制到src/main/assets/fonts ,同样在 IOS 的Resources文件夹中

The fonts work fine on IOS but on android only Bold works but the Italic or Regular or any other font it doesnt work.这些字体在 IOS 上工作正常,但在 Android 上只有 Bold 工作,但 Italic 或 Regular 或任何其他字体都不起作用。

I have tried to set the fontFamily to the name property of the font but still no change我试图将fontFamily设置为字体的名称属性,但仍然没有改变

This is how I set my font variable这就是我设置字体变量的方式

export const Fonts = {
    //Working on IOS but not on Android
    //I have tried `FiraSans-Italic` `Fira Sans Italic` and nothing works
    FiraSansItalic: (Platform.OS === 'ios') ? "FiraSans-Italic" : 'Fira Sans Italic',

    //Bold works fine for both platforms
    FiraSansBold: (Platform.OS === 'ios') ? "FiraSans-Bold" : "FiraSans-Bold"
}

Any ideas what could be wrong?任何想法可能是错的?

Thank you谢谢

For someone who got the same problem make sure you're not applying any of these ( fontWeight or fontStyle ) style to your textStyle if you do so it will drop your custom font style from your text.对于遇到同样问题的人,请确保您没有将这些( fontWeightfontStyle )样式应用到您的 textStyle 中,如果这样做,它会从您的文本中删除您的自定义字体样式。

Check the filename for Android, android need to refer to the file name rather than font family name.检查Android的文件名,android需要引用文件名而不是字体系列名称。 Also make sure to set a key to your text/textInput component to make the customized font render properly after changing to a new font.还要确保为 text/textInput 组件设置一个key ,以使自定义字体在更改为新字体后正确呈现。 (Android may still render old font if you don't do so) (如果您不这样做,Android 可能仍会呈现旧字体)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM