@expo/vector-icons
Advanced tools
Comparing version 10.1.1-alpha.0 to 10.1.1-alpha.1
@@ -1,2 +0,1 @@ | ||
import { Platform } from './react-native'; | ||
import createMultiStyleIconSet from './create-multi-style-icon-set'; | ||
@@ -32,8 +31,6 @@ | ||
function createFontAwesomeStyle(style, fontWeight, family = fontFamily) { | ||
let styleName = style; | ||
function createFontAwesomeStyle(styleName, fontWeight, family = fontFamily) { | ||
let fontFile = `FontAwesome5_${pro ? `Pro_${styleName}` : styleName}.ttf`; | ||
if (styleName === 'Brands') { | ||
styleName = 'Regular'; | ||
fontFile = 'FontAwesome5_Brands.ttf'; | ||
@@ -45,8 +42,5 @@ } | ||
fontFile, | ||
fontStyle: Platform.select({ | ||
ios: { | ||
fontWeight, | ||
}, | ||
default: {}, | ||
}), | ||
fontStyle: { | ||
fontWeight, | ||
}, | ||
glyphMap, | ||
@@ -57,9 +51,9 @@ }; | ||
const brandIcons = createFontAwesomeStyle( | ||
'Brands', | ||
'Regular', | ||
'400', | ||
'FontAwesome5Brands' | ||
'FontAwesome5Brands', | ||
); | ||
const lightIcons = createFontAwesomeStyle('Light', '300'); | ||
const lightIcons = createFontAwesomeStyle('Light', '100'); | ||
const regularIcons = createFontAwesomeStyle('Regular', '400'); | ||
const solidIcons = createFontAwesomeStyle('Solid', '900'); | ||
const solidIcons = createFontAwesomeStyle('Solid', '700'); | ||
const Icon = createMultiStyleIconSet( | ||
@@ -76,3 +70,3 @@ { | ||
glyphValidator, | ||
} | ||
}, | ||
); | ||
@@ -79,0 +73,0 @@ |
@@ -6,3 +6,3 @@ import createIconSet from './create-icon-set'; | ||
fontFamilyArg, | ||
fontFile | ||
fontFile, | ||
) { | ||
@@ -9,0 +9,0 @@ const glyphMap = {}; |
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
NativeModules, | ||
Platform, | ||
PixelRatio, | ||
processColor, | ||
Text, | ||
} from './react-native'; | ||
import { NativeModules, Platform, PixelRatio, processColor, Text } from 'react-native'; | ||
import ensureNativeModuleAvailable from './ensure-native-module-available'; | ||
import createIconSourceCache from './create-icon-source-cache'; | ||
import createIconButtonComponent from './icon-button'; | ||
@@ -35,3 +28,3 @@ import createTabBarItemIOSComponent from './tab-bar-item-ios'; | ||
const fontReference = Platform.select({ | ||
windows: `/Assets/${fontFile}#${fontFamily}`, | ||
windows: `Assets/${fontFile}#${fontFamily}`, | ||
android: fontBasename, | ||
@@ -45,4 +38,2 @@ web: fontBasename, | ||
class Icon extends PureComponent { | ||
root = null; | ||
static propTypes = { | ||
@@ -62,2 +53,4 @@ allowFontScaling: PropTypes.bool, | ||
root = null; | ||
setNativeProps(nativeProps) { | ||
@@ -104,13 +97,5 @@ if (this.root) { | ||
const imageSourceCache = createIconSourceCache(); | ||
const imageSourceCache = {}; | ||
function resolveGlyph(name) { | ||
const glyph = glyphMap[name] || '?'; | ||
if (typeof glyph === 'number') { | ||
return String.fromCharCode(glyph); | ||
} | ||
return glyph; | ||
} | ||
function getImageSourceSync( | ||
function getImageSource( | ||
name, | ||
@@ -122,63 +107,50 @@ size = DEFAULT_ICON_SIZE, | ||
const glyph = resolveGlyph(name); | ||
const processedColor = processColor(color); | ||
const cacheKey = `${glyph}:${size}:${processedColor}`; | ||
if (imageSourceCache.has(cacheKey)) { | ||
return imageSourceCache.get(cacheKey); | ||
let glyph = glyphMap[name] || '?'; | ||
if (typeof glyph === 'number') { | ||
glyph = String.fromCharCode(glyph); | ||
} | ||
try { | ||
const imagePath = NativeIconAPI.getImageForFontSync( | ||
fontReference, | ||
glyph, | ||
size, | ||
processedColor | ||
); | ||
const value = { uri: imagePath, scale: PixelRatio.get() }; | ||
imageSourceCache.setValue(cacheKey, value); | ||
return value; | ||
} catch (error) { | ||
imageSourceCache.setError(cacheKey, error); | ||
throw error; | ||
} | ||
} | ||
async function getImageSource( | ||
name, | ||
size = DEFAULT_ICON_SIZE, | ||
color = DEFAULT_ICON_COLOR | ||
) { | ||
ensureNativeModuleAvailable(); | ||
const glyph = resolveGlyph(name); | ||
const processedColor = processColor(color); | ||
const cacheKey = `${glyph}:${size}:${processedColor}`; | ||
const scale = PixelRatio.get(); | ||
if (imageSourceCache.has(cacheKey)) { | ||
return imageSourceCache.get(cacheKey); | ||
} | ||
try { | ||
const imagePath = await NativeIconAPI.getImageForFont( | ||
fontReference, | ||
glyph, | ||
size, | ||
processedColor | ||
); | ||
const value = { uri: imagePath, scale: PixelRatio.get() }; | ||
imageSourceCache.setValue(cacheKey, value); | ||
return value; | ||
} catch (error) { | ||
imageSourceCache.setError(cacheKey, error); | ||
throw error; | ||
} | ||
return new Promise((resolve, reject) => { | ||
const cached = imageSourceCache[cacheKey]; | ||
if (typeof cached !== 'undefined') { | ||
if (!cached || cached instanceof Error) { | ||
reject(cached); | ||
} else { | ||
resolve({ uri: cached, scale }); | ||
} | ||
} else { | ||
NativeIconAPI.getImageForFont( | ||
fontReference, | ||
glyph, | ||
size, | ||
processedColor, | ||
(err, image) => { | ||
const error = typeof err === 'string' ? new Error(err) : err; | ||
imageSourceCache[cacheKey] = image || error || false; | ||
if (!error && image) { | ||
resolve({ uri: image, scale }); | ||
} else { | ||
reject(error); | ||
} | ||
} | ||
); | ||
} | ||
}); | ||
} | ||
async function loadFont(file = fontFile) { | ||
function loadFont(file = fontFile) { | ||
if (Platform.OS === 'ios') { | ||
ensureNativeModuleAvailable(); | ||
if (!file) { | ||
throw new Error('Unable to load font, because no file was specified. '); | ||
return Promise.reject( | ||
new Error('Unable to load font, because no file was specified. ') | ||
); | ||
} | ||
await NativeIconAPI.loadFontWithFileName(...file.split('.')); | ||
return NativeIconAPI.loadFontWithFileName(...file.split('.')); | ||
} | ||
return Promise.resolve(); | ||
} | ||
@@ -209,3 +181,2 @@ | ||
Icon.getImageSource = getImageSource; | ||
Icon.getImageSourceSync = getImageSourceSync; | ||
Icon.loadFont = loadFont; | ||
@@ -212,0 +183,0 @@ Icon.hasIcon = hasIcon; |
@@ -30,3 +30,3 @@ import React, { PureComponent } from 'react'; | ||
style.fontFile || '', | ||
style.fontStyle || {} | ||
style.fontStyle || {}, | ||
); | ||
@@ -43,3 +43,3 @@ | ||
: result, | ||
options.defaultStyle | ||
options.defaultStyle, | ||
); | ||
@@ -91,3 +91,3 @@ } | ||
color = DEFAULT_ICON_COLOR, | ||
style = options.defaultStyle | ||
style = options.defaultStyle, | ||
) { | ||
@@ -94,0 +94,0 @@ return getStyledIconSet(style, name).getImageSource(name, size, color); |
@@ -1,2 +0,2 @@ | ||
import { Platform, NativeModules } from './react-native'; | ||
import { Platform, NativeModules } from 'react-native'; | ||
@@ -3,0 +3,0 @@ const NativeIconAPI = |
@@ -55,3 +55,3 @@ const _ = require('lodash'); | ||
if (template) { | ||
return _.template(template)({ glyphMap: content, ...data }); | ||
return _.template(template)(Object.assign({ glyphMap: content }, data)); | ||
} | ||
@@ -58,0 +58,0 @@ return content; |
@@ -6,3 +6,3 @@ import isString from 'lodash/isString'; | ||
import PropTypes from 'prop-types'; | ||
import { StyleSheet, Text, TouchableHighlight, View } from './react-native'; | ||
import { StyleSheet, Text, TouchableHighlight, View } from 'react-native'; | ||
@@ -9,0 +9,0 @@ const styles = StyleSheet.create({ |
@@ -6,3 +6,3 @@ /* eslint-disable react/no-unused-prop-types */ | ||
import PropTypes from 'prop-types'; | ||
import { TabBarIOS } from './react-native'; | ||
import { TabBarIOS } from 'react-native'; | ||
@@ -9,0 +9,0 @@ const ICON_PROP_NAMES = ['iconName', 'iconSize', 'iconColor']; |
@@ -6,3 +6,3 @@ /* eslint-disable react/no-unused-prop-types */ | ||
import PropTypes from 'prop-types'; | ||
import ToolbarAndroid from '@react-native-community/toolbar-android'; | ||
import { ToolbarAndroid } from 'react-native'; | ||
@@ -9,0 +9,0 @@ const ICON_PROP_NAMES = ['iconSize', 'iconColor', 'titleColor']; |
{ | ||
"name": "@expo/vector-icons", | ||
"sideEffects": false, | ||
"version": "10.1.1-alpha.0", | ||
"version": "10.1.1-alpha.1", | ||
"description": "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.", | ||
@@ -6,0 +6,0 @@ "main": "build/IconsLazy.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
173
2973386
20824