From d9de8f8f050bde66407bea27dcd92a9f14ee29a4 Mon Sep 17 00:00:00 2001 From: Roi Nagar Date: Thu, 1 Dec 2022 19:50:39 +0200 Subject: [PATCH] Migrate to componentDidUpdate Closing #12 --- index.js | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 5bc00d6..797a7fb 100644 --- a/index.js +++ b/index.js @@ -96,20 +96,20 @@ export default class SlotMachine extends Component { setTimeout(this.startInitialAnimation, delay); } - componentWillReceiveProps(newProps) { - if (newProps.text === this.text) { - return; + componentDidUpdate(prevProps) { + if (prevProps.text === this.props.text) { + return; } - this.text = newProps.text; - const {range, duration, useNativeDriver} = newProps; + this.text = this.props.text; + const {range, duration, useNativeDriver} = this.props; const easing = Easing.inOut(Easing.ease); - const paddedStr = this.getPaddedString(newProps); - const newValues = this.getAdjustedAnimationValues(newProps); + const paddedStr = this.getPaddedString(this.props); + const newValues = this.getAdjustedAnimationValues(this.props); this.setState({values: newValues}, () => { const newAnimations = paddedStr.split('').map((char, i) => { const index = range.indexOf(char); - const animationValue = -1 * (index) * newProps.height; + const animationValue = -1 * index * this.props.height; return Animated.timing(this.state.values[i], {toValue: animationValue, duration, easing, useNativeDriver: useNativeDriver}); }); Animated.parallel(newAnimations).start(); diff --git a/package.json b/package.json index 1ae1227..a5f8277 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-slot-machine", - "version": "0.3.2", + "version": "0.4.0", "description": "A slot machine component for React Native", "main": "index.js", "scripts": {