探索React Native的星级评分组件:react-native-star-rating
import React from 'react';
import { StyleSheet, View } from 'react-native';
import StarRating from 'react-native-star-rating';
export default class StarRatingExample extends React.Component {
constructor(props) {
super(props);
this.state = {
starCount: 3.5,
};
}
render() {
return (
<View style={styles.container}>
<StarRating
disabled={false}
maxStars={5}
starSize={40}
starColor={'gold'}
selectedStar={this.state.starCount}
fullStarImage={require('./img/star.png')}
emptyStarImage={require('./img/star_border.png')}
halfStarImage={require('./img/star_half.png')}
onStarChange={(nextValue) => this.setState({ starCount: nextValue })}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
这段代码展示了如何在React Native应用程序中使用react-native-star-rating
组件。它定义了一个名为StarRatingExample
的React组件,其中包含一个星级评分组件,可以让用户选择评分。星星图片是自定义的,并且可以通过onStarChange
回调来处理评分变化事件。
评论已关闭