react-native-vector-icons: cannot load icons in android
Environment
android, react-native 0.61.5, react-native-vector-icons 6.6.0, react-native-navigation v4
Description
I used rnn v4 and setting on tab icons.
import { PixelRatio } from 'react-native';
import DefaultIconProvider from 'react-native-vector-icons/EvilIcons';
import { isIphone } from 'constants/deviceinfo';
const navIconSize = isIphone ? 35 : PixelRatio.getPixelSizeForLayoutSize(35);
// Remove size string
const replaceSuffixPattern = /--(active|big|small|very-big)/g;
const icons = {
'sc-youtube': [navIconSize],
user: [navIconSize],
gear: [navIconSize],
search: [25],
'chevron-right': [25],
};
const iconsSource = new Map();
const iconsLoaded = async () => {
const sources = await Promise.all(
Object.keys(icons).map(iconName => {
const Provider = icons[iconName][1] || DefaultIconProvider;
return Provider.getImageSource(
iconName.replace(replaceSuffixPattern, ''),
icons[iconName][0],
);
}),
);
Object.keys(icons).forEach((iconName, idx) => (iconsSource[iconName] = sources[idx]));
return true;
};
(This is how I load icons for use tab button icons)
follow instructions and other solution issues, but simulators and real devices cant load icons like this.
I try to reinstall with cleaning project and also move to new react-native project, but don’t know why still can’t load icons.
Does anyone know a solution to this problem??
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 19 (2 by maintainers)
Use this commandyarn react-native link react-native-vector-iconsthis will transfer all the files necessary to load the fonts in both android & ios folder.Automatic way to add fonts
Add this piece of code in
android\app\build.gradle. I only want MaterialCommunityIcons.ttf if you want other font add them here it will be added automatically.This is manual way (If automatic didn’t work)
Step 1
Move the .ttf file from the
node_modules\react-native-vector-icons\Fontsthat you want toandroid\app\src\main\assets\fontsafter thatcd androidand run./gradlew cleanorgradlew cleanStep 2
Add this line in
android\app\build.gradleAfter that the icons will be visible. Try resetting the cache if it did not work
yarn react-native start --reset-cache&yarn react-native run-androidreact-native link and re-run project works for me.
See this… https://www.npmjs.com/package/react-native-vector-icons
@yuertongle link is deprecated use autolinking. Check my solution. RN 60 onwards the native dependencies get autolinked.
I was getting this issue in my project. The solution here was: delete the old APK and reinstall a new one. Seems like a font cache.
It works for me, thanks! I guess adding
project.ext.vectoriconsis the critical solution. Do not usereact-native link, it leads to errors