From 337e837537f91724ecad5665362c44dcb14e7d8a Mon Sep 17 00:00:00 2001 From: Todor Ivanov Date: Fri, 13 Jul 2018 18:32:34 +0300 Subject: [PATCH 1/2] - Adding ability to update stars rating from outside --- src/rating.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/rating.js b/src/rating.js index c2836dc..70c3a66 100644 --- a/src/rating.js +++ b/src/rating.js @@ -89,11 +89,18 @@ export default class Rating extends PureComponent { constructor(props) { super(props) + debugger this.state = { selected: props.initial } } + + componentWillReceiveProps(nextProps) { + debugger + this.animate(nextProps.initial, false)() + } + getSelectedOpacity = index => this.animatedValues[index].interpolate({ inputRange: [0, 1], @@ -117,15 +124,19 @@ 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 + debugger const animations = createAnimations(config, this.animatedValues, this.state.selected, curr) this.setState( () => ({ selected: curr }), () => { - onChange(this.state.selected) + debugger + if (shouldReload) { + onChange(this.state.selected) + } Animated.stagger(stagger, animations).start(() => onAnimationComplete(this.state.selected)) } ) @@ -135,7 +146,7 @@ export default class Rating extends PureComponent { From d2bdf185e43ba0767d3d7eb2a45dff4214535a2f Mon Sep 17 00:00:00 2001 From: Todor Ivanov Date: Fri, 13 Jul 2018 18:36:21 +0300 Subject: [PATCH 2/2] - Removed debuggers --- src/rating.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/rating.js b/src/rating.js index 70c3a66..32ddeb2 100644 --- a/src/rating.js +++ b/src/rating.js @@ -89,7 +89,6 @@ export default class Rating extends PureComponent { constructor(props) { super(props) - debugger this.state = { selected: props.initial } @@ -97,7 +96,6 @@ export default class Rating extends PureComponent { componentWillReceiveProps(nextProps) { - debugger this.animate(nextProps.initial, false)() } @@ -126,14 +124,12 @@ export default class Rating extends PureComponent { animate = (curr, shouldReload) => () => { const { config, stagger, onChange, onAnimationComplete } = this.props - debugger const animations = createAnimations(config, this.animatedValues, this.state.selected, curr) this.setState( () => ({ selected: curr }), () => { - debugger if (shouldReload) { onChange(this.state.selected) }