UNPKG

@expo/vector-icons

Version:

Built-in support for popular icon fonts and the tooling to create your own Icon components from your font and glyph map. This is a wrapper around react-native-vector-icons to make it compatible with Expo.

74 lines (62 loc) 1.82 kB
import createMultiStyleIconSet from './create-multi-style-icon-set'; const FA5Style = { regular: 'regular', light: 'light', solid: 'solid', brand: 'brand', }; function createFA5iconSet(glyphMap, metadata = {}, pro = false) { const metadataKeys = Object.keys(metadata); const fontFamily = `FontAwesome5${pro ? 'Pro' : 'Free'}`; function fallbackFamily(glyph) { for (let i = 0; i < metadataKeys.length; i += 1) { const family = metadataKeys[i]; if (metadata[family].indexOf(glyph) !== -1) { return family === 'brands' ? 'brand' : family; } } return 'regular'; } function glyphValidator(glyph, style) { const family = style === 'brand' ? 'brands' : style; if (metadataKeys.indexOf(family) === -1) return false; return metadata[family].indexOf(glyph) !== -1; } function createFontAwesomeStyle(styleName, fontWeight, family = fontFamily) { let fontFile = `FontAwesome5_${pro ? `Pro_${styleName}` : styleName}.ttf`; if (styleName === 'Brands') { fontFile = 'FontAwesome5_Brands.ttf'; } return { fontFamily: `${family}-${styleName}`, fontFile, fontStyle: { fontWeight, }, glyphMap, }; } const brandIcons = createFontAwesomeStyle( 'Regular', '400', 'FontAwesome5Brands', ); const lightIcons = createFontAwesomeStyle('Light', '100'); const regularIcons = createFontAwesomeStyle('Regular', '400'); const solidIcons = createFontAwesomeStyle('Solid', '700'); const Icon = createMultiStyleIconSet( { brand: brandIcons, light: lightIcons, regular: regularIcons, solid: solidIcons, }, { defaultStyle: 'regular', fallbackFamily, glyphValidator, }, ); return Icon; } export { createFA5iconSet, FA5Style };