Created
January 18, 2018 21:07
-
-
Save EQuimper/1a1ce0d36ee5f455c8d74c22ee1970cf to your computer and use it in GitHub Desktop.
Running Vector Icons for React-Native-Navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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