Skip to content
Open
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
13 changes: 10 additions & 3 deletions src/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export default class Rating extends PureComponent {
}
}


componentWillReceiveProps(nextProps) {
this.animate(nextProps.initial, false)()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling setState here should be enough ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should not be enough.
It works exactly how I implemented it.

}

getSelectedOpacity = index =>
this.animatedValues[index].interpolate({
inputRange: [0, 1],
Expand All @@ -117,15 +122,17 @@ export default class Rating extends PureComponent {

animatedValues = initializeAnimatedValues(this.props.max, this.props.initial)

animate = curr => () => {
animate = (curr, shouldReload) => () => {
const { config, stagger, onChange, onAnimationComplete } = this.props
const animations = createAnimations(config, this.animatedValues, this.state.selected, curr)
this.setState(
() => ({
selected: curr
}),
() => {
onChange(this.state.selected)
if (shouldReload) {
onChange(this.state.selected)
}
Animated.stagger(stagger, animations).start(() => onAnimationComplete(this.state.selected))
}
)
Expand All @@ -135,7 +142,7 @@ export default class Rating extends PureComponent {
<TouchableWithoutFeedback
disabled={!this.props.editable}
key={index}
onPress={this.animate(index + 1)}
onPress={this.animate((index + 1), true)}
>
<View style={this.props.starStyle}>
<View style={styles.imageContainer}>
Expand Down