font ionicons not found Expo SDK36 with NativeBase 2.13.8 and expo-font 8.1.0
I have gone through these following points
- [x] Check latest documentation: https://docs.nativebase.io/
- [x] Check for existing open/closed issues for a possible duplicate before creating a new issue: https://github.com/GeekyAnts/NativeBase/issues
- [x] Use the latest NativeBase release: https://github.com/GeekyAnts/NativeBase/releases
- [x] Check examples from NativeBase KitchenSink https://github.com/GeekyAnts/NativeBase-KitchenSink
- [] For discussion purpose make use of NativeBase Slack: http://slack.nativebase.io/
- [] For queries related to theme, check Theme Variables from Docs and live NativeBase Theme Editor http://nativebase.io/customizer/
Issue Description
node, npm, react-native, react and native-base version, expo version if used, xcode version
node: v13.9.0 npm: 6.14.4 react-native: 0.61.5 native-base: 2.13.8 expo: 36.0.0
Expected behaviour
Actual behaviour
Hello guys,
I'm facing an issue with expo and native-base:
fontFamily "ionicons" is not a system font and has not been loaded through Font.loadAsync.
Do you have any solutions about this problem? I've already followed instructions to install native-base
Thanks
Steps to reproduce
Is the bug present in both iOS and Android or in any one of them?
Android and iOS
Any other additional info which would help us debug the issue quicker.
###Important
If you want your issue to be looked at quicker, attach a snack reproducible with your issue. Makes it easier for us!
Same issue after running expo upgrade from version 35 to version 36
node: v12.6.0 npm: 6.9.0 react-native: https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz native-base: 2.13.8 expo: 36.0.2 expo-font: 8.0.0
let fonts = {
Roboto: require('native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
...FontAwesome.font,
...FontAwesome5.font
};
await Font.loadAsync(fonts);
console.log(`${_.keys(fonts).length} Fonts Loaded`)
Prints out 8 Fonts Loaded
Edit: found a solution from https://github.com/expo/expo/issues/5507
Need to install expo-font dependency and run rm -rf ./node_modules/expo/node_modules/expo-font/
Images
export const cacheImages = (images: Array<Image>, type: Type) =>
Object.values(images).map((image: Image) =>
typeof image === 'string' && type === Type.image
? ImageComponent.prefetch(image)
: Asset.fromModule(image).downloadAsync(),
);
Fonts
import * as Font from 'expo-font';
export const cacheFonts = fonts =>
fonts.map(font => Font.loadAsync({ [font.name]: font.uri }));
import { Ionicons } from '@expo/vector-icons';
// LOCAL
const firefox = 'firefox';
export const ionicons: string = Ionicons.font['ionicons'];
export const resources: Array<IFonts> = [
{ name: 'Roboto', uri: roboto, blackList: [firefox] },
{ name: 'Roboto_medium', uri: robotoMedium, blackList: [firefox] },
{ name: 'ionicons', uri: ionicons, blackList: [] },
].filter(font => (font.blackList.includes(firefox))? null: font );
Async Assets Here I do the static load
const loadAssetsAsync = async () => {
const fontAssets = cacheFonts(fonts.resources);
const imageAssets = cacheImages(images.resources, Type.image);
return Promise.all([...fontAssets, ...imageAssets]);
};
App.tsx In my app.tsx I have put a try catch finally with a class component and not functional, it works better for me so using a useEffect.
import React from 'react';
import { AppLoading } from 'expo';
import { logWarning } from './src/utils/console-warn';
import { loadAssetsAsync } from './src/constants/index';
import Main from './src/main';
class App extends React.Component {
state = {
fontLoaded: false
}
async componentDidMount() {
try {
// for warning react native unsafe lifecycle
console.warn = logWarning;
await loadAssetsAsync();
} catch (e) {
console.warn(
'There was an error caching assets (see: main.js), perhaps due to a ' +
'network timeout, so we skipped caching. Reload the app to try again.' +
e.message
);
} finally {
this.setState({ fontLoaded: true });
}
}
render() {
if(this.state.fontLoaded) {
return (<Main/>);
} else {
return (<AppLoading/>);
}
}
}
export default App;
adding this line to your package.json resolves this issue
"postinstall": "cp node_modules/@expo/vector-icons/FontAwesome.js node_modules/@expo/vector-icons/Fontisto.js"
if you are using any of these libraries i found that they make conflict
react-native-svg or react-native-svg-transformer.
If so, then remove them using yarn remove or npm uninstall.
Also, if you have the file called metro.config.js,
remove it and its link in the app.json, "config": "metro.config.js"
Hi @Starkiller75000 , please update with NativeBase v2.13.14 . Let us know if the issue still persists
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.