-
Notifications
You must be signed in to change notification settings - Fork 141
/
SMXIconImage.ios.js
83 lines (65 loc) · 1.92 KB
/
SMXIconImage.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
*
* @providesModule SMXIconImage
* @flow
*/
'use strict';
var React = require('react-native');
var { StyleSheet, View, requireNativeComponent, processColor } = React;
var shimAssert = require('./shim-assert');
var ICON_REF = 'icon';
var SMXIconImage = React.createClass({
propTypes: {
name: React.PropTypes.string,
size: React.PropTypes.number,
color: React.PropTypes.string,
/**
* accessible - Whether this element should be revealed as an accessible
* element.
*/
accessible: React.PropTypes.bool,
/**
* accessibilityLabel - Custom string to display for accessibility.
*/
accessibilityLabel: React.PropTypes.string,
/**
* testID - A unique identifier for this element to be used in UI Automation
* testing scripts.
*/
testID: React.PropTypes.string,
icon: React.PropTypes.object
},
setNativeProps(props:Object) {
this.refs[ICON_REF].setNativeProps(props);
},
render: function () {
var style = [styles.base, this.props.style];
shimAssert.basic( style, 'style must be initialized');
var name = this.props.name;
shimAssert.basic( name, 'name must be initialized');
var size = this.props.size;
shimAssert.basic( size, 'size must be initialized');
if(name.indexOf('|') == -1) {
throw Error('icon name "' + name + '" doesn\'t specify a font prefix. ex. "ion|beer"');
}
var color = this.props.color;
var nativeProps = Object.assign({},this.props);
if(!color && style.color) {
color = style.color;
}
nativeProps.style = style;
nativeProps.icon = {
name: name,
size: size,
color: processColor(color)
};
return <SMXIconImageView {...nativeProps} ref={ICON_REF} />;
}
});
var styles = StyleSheet.create({
base: {
overflow: 'hidden'
}
});
var SMXIconImageView = requireNativeComponent('FAKIconImage', SMXIconImage);
module.exports = SMXIconImage;