forked from djchie/react-native-star-rating
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstar-button.js
81 lines (71 loc) · 2.2 KB
/
star-button.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
// React and react native imports
import React, {
Component,
PropTypes,
} from 'react';
import { View } from 'react-native';
// Third party imports
import Button from 'react-native-button';
import EntypoIcons from 'react-native-vector-icons/Entypo';
import EvilIconsIcons from 'react-native-vector-icons/EvilIcons';
import FontAwesomeIcons from 'react-native-vector-icons/FontAwesome';
import FoundationIcons from 'react-native-vector-icons/Foundation';
import IoniconsIcons from 'react-native-vector-icons/Ionicons';
import MaterialIconsIcons from 'react-native-vector-icons/MaterialIcons';
import OcticonsIcons from 'react-native-vector-icons/Octicons';
import ZocialIcons from 'react-native-vector-icons/Zocial';
import MaterialCommunityIconsIcons from 'react-native-vector-icons/MaterialCommunityIcons';
const iconSets = {
Entypo: EntypoIcons,
EvilIcons: EvilIconsIcons,
FontAwesome: FontAwesomeIcons,
Foundation: FoundationIcons,
Ionicons: IoniconsIcons,
MaterialIcons: MaterialIconsIcons,
Octicons: OcticonsIcons,
Zocial: ZocialIcons,
MaterialCommunityIcons: MaterialCommunityIconsIcons,
};
class StarButton extends Component {
constructor(props) {
super(props);
this.onButtonPress = this.onButtonPress.bind(this);
}
onButtonPress() {
this.props.onStarButtonPress(this.props.rating);
}
render() {
const Icon = iconSets[this.props.iconSet];
return (
<Button
activeOpacity={0.20}
disabled={this.props.disabled}
onPress={this.onButtonPress}
containerStyle={this.props.buttonStyle}
style={{
height: this.props.starSize,
width: this.props.starSize,
}}
>
<Icon
name={this.props.starIconName}
size={this.props.starSize}
color={this.props.starColor}
style={this.props.starStyle}
/>
</Button>
);
}
}
StarButton.propTypes = {
disabled: PropTypes.bool,
rating: PropTypes.number,
onStarButtonPress: PropTypes.func,
iconSet: PropTypes.string,
starSize: PropTypes.number,
starIconName: PropTypes.string,
starColor: PropTypes.string,
starStyle: View.propTypes.style,
buttonStyle: View.propTypes.style,
};
export default StarButton;