Skip to content

Instantly share code, notes, and snippets.

@EQuimper
Created January 18, 2018 21:07
Show Gist options
  • Save EQuimper/1a1ce0d36ee5f455c8d74c22ee1970cf to your computer and use it in GitHub Desktop.
Save EQuimper/1a1ce0d36ee5f455c8d74c22ee1970cf to your computer and use it in GitHub Desktop.
Running Vector Icons for React-Native-Navigation
import React from 'react';
import Entypo from 'react-native-vector-icons/Entypo'
import { Platform, PixelRatio } from 'react-native';
const navIconSize = (__DEV__ === false && Platform.OS === 'android') ? PixelRatio.getPixelSizeForLayoutSize(25) : 25;
const replaceSuffixPattern = /--(active|big|small|very-big)/g;
const icons = {
home: [navIconSize, Entypo],
};
const iconsMap = {};
const iconsLoaded = new Promise((resolve, reject) => {
new Promise.all(
Object.keys(icons).map(iconName => {
const Provider = icons[iconName][1] || defaultIconProvider;
return Provider.getImageSource(
iconName.replace(replaceSuffixPattern, ''),
icons[iconName][0],
);
}),
).then(sources => {
Object.keys(icons).forEach(
(iconName, idx) => (iconsMap[iconName] = sources[idx]),
);
resolve(true);
});
});
export { iconsMap, iconsLoaded };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment