-
-
Save jason-shen/d2c2acde601d259aa0aaf9cf2befcf8a to your computer and use it in GitHub Desktop.
Running Vector Icons for React-Native-Navigation
This file contains 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