Skip to content

Commit

Permalink
Merge pull request #15 from atlanteh/feature/migrate-to-componentDidU…
Browse files Browse the repository at this point in the history
…pdate

Migrate to componentDidUpdate
  • Loading branch information
atlanteh authored Dec 3, 2022
2 parents 69d4cad + d9de8f8 commit e52041d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit e52041d

Please sign in to comment.