forked from ksti/react-native-star-rating-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarsView.js
53 lines (45 loc) · 1.35 KB
/
StarsView.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
import React, { PureComponent } from 'react';
import { View } from 'react-native';
import StarView from './StarView';
import styles from './styles';
class StarsView extends PureComponent {
render() {
const {
value, allowsHalfStars, accurateHalfStars, spacing, starStyle,
emptyStarColor, tintColor, emptyStarImage, filledStarImage, starWidth,
validMaximumValue,
} = this.props;
const stars = [];
for (let idx = 0; idx < validMaximumValue; idx++) {
const highlighted = (idx + 1 <= Math.ceil(value));
let renderProgress = 0;
if (allowsHalfStars && highlighted && (idx + 1 > value)) {
if (accurateHalfStars) {
renderProgress = value - idx;
} else {
renderProgress = 0.5;
}
} else {
renderProgress = highlighted ? 1 : 0;
}
stars.push(
<StarView
key={`StarView_id_${idx}`}
style={[starStyle, idx < validMaximumValue - 1 && { marginRight: spacing }]}
emptyStarColor={emptyStarColor}
tintColor={tintColor}
emptyStarImage={emptyStarImage}
filledStarImage={filledStarImage}
progress={renderProgress}
starWidth={starWidth}
/>
);
}
return (
<View style={styles.starContainer}>
{stars}
</View>
);
}
}
export default StarsView;