From e2666877e916a338ff01da2d5b6b40f9057ace16 Mon Sep 17 00:00:00 2001 From: Pavel Zarecky Date: Mon, 2 Sep 2019 17:53:27 +0200 Subject: [PATCH] * componentWillMount and componentWillReceiveProps refactored --- src/Slider.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Slider.js b/src/Slider.js index f2c43654..e206b324 100644 --- a/src/Slider.js +++ b/src/Slider.js @@ -182,15 +182,17 @@ export default class Slider extends PureComponent { animationType: 'timing', }; - state = { - containerSize: { width: 0, height: 0 }, - trackSize: { width: 0, height: 0 }, - thumbSize: { width: 0, height: 0 }, - allMeasured: false, - value: new Animated.Value(this.props.value), - }; + constructor(props) { + super(props); + + this.state = { + containerSize: { width: 0, height: 0 }, + trackSize: { width: 0, height: 0 }, + thumbSize: { width: 0, height: 0 }, + allMeasured: false, + value: new Animated.Value(props.value), + }; - componentWillMount() { this._panResponder = PanResponder.create({ onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder, onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder, @@ -202,14 +204,12 @@ export default class Slider extends PureComponent { }); } - componentWillReceiveProps(nextProps) { - const newValue = nextProps.value; - - if (this.props.value !== newValue) { + componentDidUpdate({value}) { + if (this.props.value !== value) { if (this.props.animateTransitions) { - this._setCurrentValueAnimated(newValue); + this._setCurrentValueAnimated(this.props.value); } else { - this._setCurrentValue(newValue); + this._setCurrentValue(this.props.value); } } }