-
Notifications
You must be signed in to change notification settings - Fork 15
/
Icon.js
104 lines (97 loc) · 2.87 KB
/
Icon.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React, { Component } from 'react';
import {
ActivityIndicator,
Image,
StyleSheet,
View,
ViewPropTypes,
} from 'react-native';
import PropTypes from 'proptypes';
export default class Icon extends Component {
static propTypes = {
containerStyle: ViewPropTypes.style,
imageStyle: Image.propTypes.style,
name: PropTypes.string,
source: Image.propTypes.source,
};
render() {
let source;
let icon;
if (this.props.source) {
source = this.props.source;
} else if (this.props.name) {
switch (this.props.name) {
case 'back':
source = require('./ActionBarImages/back.png');
break;
case 'flag':
source = require('./ActionBarImages/flag.png');
break;
case 'loading':
icon = (<ActivityIndicator />);
break;
case 'location':
source = require('./ActionBarImages/location.png');
break;
case 'menu':
source = require('./ActionBarImages/menu.png');
break;
case 'phone':
source = require('./ActionBarImages/phone.png');
break;
case 'plus':
source = require('./ActionBarImages/plus.png');
break;
case 'star':
source = require('./ActionBarImages/star.png');
break;
case 'star-outline':
source = require('./ActionBarImages/star_outline.png');
break;
case 'none':
// Don't render anything
return null;
default:
if (__DEV__) {
console.log(`${this.props.name} is an invalid icon name. Did you want to say 'none'?`);
}
return null;
}
}
if (source && !icon) {
icon = (
<Image
style={[
styles.icon,
this.props.imageStyle,
]}
source={source}
/>
);
}
return (
<View
style={[
styles.container,
this.props.containerStyle,
]}
>
{icon}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
width: 40,
height: 40,
justifyContent: 'center',
alignItems: 'center',
},
icon: {
width: 20,
height: 20,
resizeMode: 'contain',
tintColor: '#FFFFFF',
},
});