Initial commit

fbshipit-source-id: 21ada2db87c55eb346aa4da5b67d25cb1c8fd081
This commit is contained in:
Exponent GitHub Bot
2016-07-10 02:20:06 +00:00
commit 6bd475399a
21 changed files with 128 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import React from 'react';
import { View } from 'react-native';
import { Font } from 'exponent';
import createIconSet from 'react-native-vector-icons/lib/create-icon-set';
export default function(glyphMap, fontName, exponentAssetId) {
const exponentFontName = Font.style(fontName, {ignoreWarning: true}).fontFamily;
const fontId = {[fontName]: exponentAssetId};
let OriginalIcon = createIconSet(glyphMap, exponentFontName, 'n/a');
class Icon extends React.Component {
static propTypes = OriginalIcon.propTypes;
static defaultProps = OriginalIcon.defaultProps;
state = {
fontIsLoaded: Font.isLoaded(fontName),
}
async componentWillMount() {
if (!this.state.fontIsLoaded) {
await Font.loadAsync(fontId);
this.setState({fontIsLoaded: true});
}
}
setNativeProps(props) {
if (this._icon) {
this._icon.setNativeProps(props);
}
}
render() {
if (!this.state.fontIsLoaded) {
return <View />;
}
return (
<OriginalIcon
ref={view => { this._icon = view; }}
{...this.props}
/>
);
}
}
return Icon;
}