-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Rating.js
28 lines (25 loc) · 820 Bytes
/
Rating.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
import * as React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { AntDesign } from '@expo/vector-icons';
export default function Rating({ rating }) {
const filledStars = Math.floor(rating / 2);
const maxStars = Array(5 - filledStars).fill('staro');
const r = [...Array(filledStars).fill('star'), ...maxStars];
return (
<View style={styles.rating}>
<Text style={styles.ratingNumber}>{rating}</Text>
{r.map((type, index) => {
return <AntDesign key={index} name={type} size={12} color="tomato" />;
})}
</View>
);
}
const styles = StyleSheet.create({
ratingNumber: { marginRight: 4, fontFamily: 'Menlo', fontSize: 14 },
rating: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
marginVertical: 4
},
});