Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support change the background by select #85

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,57 @@ export default GeneralStarExample
<img src="https://github.com/djchie/react-native-star-rating/blob/master/assets/general-star-demo.gif" alt="General Star Example" width="336" height="600"/>
</p>

### Custom Star Case
### Custom Star Case 1
The following example could change star button background color by your select.
<p align="center">
<img width="409" alt="image" src="https://user-images.githubusercontent.com/6138872/60478520-87a10080-9cb5-11e9-8989-8871862761dc.png">
</p>

```js
import StarRating from 'react-native-star-rating';

class CustomStarExample extends Component {

constructor(props) {
super(props);
this.state = {
starCount: 3
};
}

onStarRatingPress(rating) {
this.setState({
starCount: rating
});
}

render() {
return (
<StarRating
activeOpacity={0.6}
disabled={false}
maxStars={5}
rating={this.state.starCount}
selectedStar={(rating) => this.onStarRatingPress(rating)}
buttonStyle={styles.ratingButton}
fullStarColor={'white'}
emptyStarColor={'white'}
emptyStar={'meh-o'}
fullStar={'meh-o'}
starSize = {20}
fullStarBackgroundColor={'#FFC64B'}
emptyStarBackgroundColor={'#EBEBEB'}
/>
);
}
}

export default CustomStarExample
```



### Custom Star Case 2

The following example will render 2.5 stars out of 7 stars using the `ios-star-outline` for the empty star icon, `ios-star-half` for the half star icon, and `ios-star` for the full star icon from the `Ionicons` icon set in red color.

Expand Down
13 changes: 12 additions & 1 deletion StarRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ const defaultProps = {
disabled: false,
emptyStar: 'star-o',
emptyStarColor: 'gray',
emptyStarBackgroundColor:'#00000000',
fullStar: 'star',
fullStarColor: 'black',
fullStarBackgroundColor:'#00000000',
halfStar: 'star-half-o',
halfStarColor: undefined,
halfStarEnabled: false,
Expand Down Expand Up @@ -102,8 +104,10 @@ class StarRating extends Component {
disabled,
emptyStar,
emptyStarColor,
emptyStarBackgroundColor,
fullStar,
fullStarColor,
fullStarBackgroundColor,
halfStar,
halfStarColor,
halfStarEnabled,
Expand All @@ -129,18 +133,25 @@ class StarRating extends Component {
for (let i = 0; i < maxStars; i++) {
let starIconName = emptyStar;
let finalStarColor = emptyStarColor;
let finalBackgroundColor = '#00000000'

if (starsLeft >= 1) {
starIconName = fullStar;
finalStarColor = fullStarColor;
finalBackgroundColor = fullStarBackgroundColor
} else if (starsLeft === 0.5) {
starIconName = halfStar;
if (halfStarColor) {
finalStarColor = halfStarColor;
finalBackgroundColor = emptyStarBackgroundColor;
} else {
finalStarColor = fullStarColor;
finalBackgroundColor = emptyStarBackgroundColor;
}
}
else {
finalBackgroundColor = emptyStarBackgroundColor;
}

const starButtonElement = (
<AnimatableView
Expand All @@ -149,7 +160,7 @@ class StarRating extends Component {
>
<StarButton
activeOpacity={activeOpacity}
buttonStyle={buttonStyle}
buttonStyle={[buttonStyle, {backgroundColor:finalBackgroundColor}]}
disabled={disabled}
halfStarEnabled={halfStarEnabled}
icoMoonJson={icoMoonJson}
Expand Down
Loading