forked from oblador/react-native-vector-icons
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split createIconSet* functions into separate files and expose them vi…
…a `@providesModule` for easier external usage.
- Loading branch information
Showing
11 changed files
with
105 additions
and
88 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @providesModule createIconSetFromFontello | ||
*/ | ||
'use strict'; | ||
|
||
var createIconSet = require('createIconSet'); | ||
|
||
function createIconSetFromFontello(config, fontFamily) { | ||
var glyphMap = {}; | ||
config.glyphs.forEach(function (glyph) { | ||
glyphMap[glyph.css] = glyph.code; | ||
}); | ||
return createIconSet(glyphMap, fontFamily || config.name) | ||
}; | ||
|
||
module.exports = createIconSetFromFontello; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* @providesModule createIconSet | ||
*/ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var React = require('react-native'); | ||
var { | ||
View, | ||
Text, | ||
StyleSheet, | ||
} = React; | ||
var merge = require('merge'); | ||
var flattenStyle = require('flattenStyle'); | ||
var ViewStylePropTypes = require('ViewStylePropTypes'); | ||
var TextStylePropTypes = require('TextStylePropTypes'); | ||
|
||
|
||
function createIconSet(glyphMap, fontFamily) { | ||
var styles = StyleSheet.create({ | ||
container: { | ||
overflow: 'hidden', | ||
backgroundColor: 'transparent', | ||
flexDirection: 'row', | ||
justifyContent: 'flex-start', | ||
alignItems: 'center', | ||
}, | ||
text: { | ||
fontFamily, | ||
} | ||
}); | ||
|
||
return React.createClass({ | ||
propTypes:{ | ||
name: React.PropTypes.oneOf(Object.keys(glyphMap)).isRequired, | ||
size: React.PropTypes.number, | ||
color: React.PropTypes.string, | ||
style: React.PropTypes.oneOfType([ | ||
React.PropTypes.number, // References to style sheets are numbers | ||
React.PropTypes.object // Inline style declaration | ||
]) | ||
}, | ||
render: function() { | ||
|
||
var name = this.props.name; | ||
var glyph = glyphMap[name] || '?'; | ||
if(typeof glyph === 'number') { | ||
glyph = String.fromCharCode(glyph); | ||
} | ||
|
||
var containerStyle = _.pick(flattenStyle([styles.container, this.props.style]), Object.keys(ViewStylePropTypes)); | ||
|
||
var textStyle = _.pick( | ||
flattenStyle([this.props.style, styles.text]), | ||
Object.keys(TextStylePropTypes) | ||
); | ||
|
||
var size = this.props.size || textStyle.fontSize || 12; | ||
textStyle.fontSize = size; | ||
textStyle.lineHeight = size; | ||
textStyle.height = size; | ||
|
||
if(this.props.color) { | ||
textStyle.color = this.props.color; | ||
} | ||
|
||
return ( | ||
<View {...this.props} style={[containerStyle]}> | ||
<Text style={textStyle}>{glyph}</Text> | ||
{this.props.children} | ||
</View> | ||
); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = createIconSet; |