Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/demo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class App extends Component {
value={this.state.value}
formatValue={this.formatValue}
duration={this.state.duration}
startFrom={5000}
/>
<hr />
<button
Expand Down
12 changes: 10 additions & 2 deletions src/lib/components/Animated-Number.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AnimatedNumber extends Component {
run: PropTypes.func,
update: PropTypes.func,
easing: PropTypes.string,
startFrom: PropTypes.number,
};

static defaultProps = {
Expand All @@ -30,13 +31,16 @@ class AnimatedNumber extends Component {
update: defaultFunction,
begin: defaultFunction,
delay: 0,
startFrom: 0,
};

state = {
animatedValue: 0,
};

componentDidMount = () => {
const { startFrom } = this.props;
target.animatedValue = startFrom;
this.animateValue();
};

Expand All @@ -45,7 +49,8 @@ class AnimatedNumber extends Component {
};

updateValue = (anima) => {
this.props.update(anima);
const { update } = this.props;
update(anima);
const { animatedValue } = target;
this.setState({ animatedValue });
};
Expand All @@ -69,7 +74,10 @@ class AnimatedNumber extends Component {
};

render() {
return <span>{this.props.formatValue(Number(this.state.animatedValue))}</span>;
const { formatValue } = this.props;
const { animatedValue } = this.state;

return <span>{formatValue(Number(animatedValue))}</span>;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/lib/components/Animated-Number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@ describe('AnimatedNumber', () => {
done();
}, 55);
});

it('should startFrom 2000', () => {
const wrapper = shallow(<AnimatedNumber value={0} startFrom={2000} />);

wrapper.update();

expect(wrapper.text()).toBe('2000');
});
});