我的应用程序可以在iOS上正确运行Expo字体,但不能在安卓上运行。我也尝试过根据docs用useFonts替换loadAsync,但都无济于事。我有两个单独的样式表,其中的baseFont属性设置了自定义字体,但由于某些原因,在其他屏幕上无法正确读取字体。使用React堆栈导航(@react- Navigation / Stack ),非登录屏幕位于不同的堆栈中。这基本上就是代码的样子:
App.js:
import RootStack from './navigations/RootStack';
import mainReducer from './reducers/index';
import { getAsyncStorage } from './actions/AuthActions';
const store = createStore(mainReducer, applyMiddleware(thunk));
store.dispatch(getAsyncStorage());
export default () => {
const [fontLoaded, setFontLoaded] = useState(false);
async function loadResourcesAsync() {
await Promise.all([
Font.loadAsync({
'custom-font': require('./assets/fonts/custom_font.ttf');
}),
]);
setFontLoaded(true);
}
useEffect(() => {
loadResourcesAsync();
});
if (!fontLoaded) return (null);
return (
<Provider store={store}>
<RootStack />
</Provider>
);
};样式/Login.js:
const styles = StyleSheet.create({
baseFont: {
fontFamily: 'custom-font',
},发布于 2021-05-27 02:16:06
事实证明,答案对于样式表中的fontWeight来说是特定的。由于自定义字体在.ttf中没有嵌入bold字体,我不得不下载粗体版本并从.ttf中删除fontWeight: bold。
https://stackoverflow.com/questions/67710065
复制相似问题