|
| 1 | +import React, {useState} from 'react'; |
| 2 | +import { StyleSheet, View, Text } from 'react-native'; |
| 3 | +import { Rating } from 'react-native-rating-element'; |
| 4 | + |
| 5 | +const App = () => { |
| 6 | + const [rating, setRating] = useState(0); |
| 7 | + const [imageRating, setImageRating] = useState(0); |
| 8 | + |
| 9 | + return ( |
| 10 | + <View style={styles.body}> |
| 11 | + <View style={styles.card}> |
| 12 | + <Text style={{fontSize: 16}}> |
| 13 | + RTL direction (4.5/5, direction="row-reverse") |
| 14 | + </Text> |
| 15 | + <View accessible accessibilityLabel={"rated 4.5 out of 5"}> |
| 16 | + <Rating |
| 17 | + rated={4.5} |
| 18 | + totalCount={5} |
| 19 | + ratingColor="#f1c644" |
| 20 | + ratingBackgroundColor="#d4d4d4" |
| 21 | + size={42} |
| 22 | + readonly |
| 23 | + icon="ios-star" |
| 24 | + direction="row-reverse" |
| 25 | + /> |
| 26 | + </View> |
| 27 | + </View> |
| 28 | + |
| 29 | + <View style={styles.card}> |
| 30 | + <Text style={{fontSize: 16}}> |
| 31 | + Interactive Rating (3/5, direction="column-reverse") |
| 32 | + </Text> |
| 33 | + <Rating |
| 34 | + rated={rating} |
| 35 | + totalCount={5} |
| 36 | + ratingColor="#f1c644" |
| 37 | + ratingBackgroundColor="#d4d4d4" |
| 38 | + size={32} |
| 39 | + icon="add-circle" |
| 40 | + direction="column-reverse" |
| 41 | + onIconTap={pos => setRating(pos)} |
| 42 | + /> |
| 43 | + <Text accessibilityLiveRegion="polite" accessibilityLabel={`Rating selected ${rating} out of 5`}>{rating}/5 (200)</Text> |
| 44 | + </View> |
| 45 | + |
| 46 | + <View style={styles.card}> |
| 47 | + <Text style={{fontSize: 16}}> |
| 48 | + Custom Images Rating |
| 49 | + </Text> |
| 50 | + <Rating |
| 51 | + rated={imageRating} |
| 52 | + totalCount={5} |
| 53 | + size={48} |
| 54 | + direction="row" |
| 55 | + type="custom" |
| 56 | + onIconTap={pos => setImageRating(pos)} |
| 57 | + selectedIconImage={require('./assets/filled.png')} |
| 58 | + emptyIconImage={require('./assets/empty.png')} |
| 59 | + /> |
| 60 | + <Text accessibilityLiveRegion="polite" accessibilityLabel={`Rating selected ${imageRating} out of 5`}>{imageRating}/5 (100)</Text> |
| 61 | + </View> |
| 62 | + |
| 63 | + </View> |
| 64 | + ); |
| 65 | +}; |
| 66 | + |
| 67 | +const styles = StyleSheet.create({ |
| 68 | + body: { |
| 69 | + backgroundColor: '#fff', |
| 70 | + flex: 1, |
| 71 | + alignItems: 'center', |
| 72 | + justifyContent: 'center', |
| 73 | + }, |
| 74 | + card: { |
| 75 | + padding: 10, |
| 76 | + borderWidth: 1, |
| 77 | + borderColor: '#eee', |
| 78 | + marginBottom: 20, |
| 79 | + }, |
| 80 | +}); |
| 81 | + |
| 82 | +export default App; |
0 commit comments