Skip to content

Commit bc2fe2a

Browse files
committed
feat(onAnimationDone): add onAnimationDone cb
1 parent 737c27b commit bc2fe2a

File tree

2 files changed

+60
-41
lines changed

2 files changed

+60
-41
lines changed

src/Animate/StackAnimates.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,51 @@ import * as Utils from './Utils';
33

44
class StackAnimates extends PureComponent {
55
constructor(props) {
6-
super(props);
6+
super(props);
77
this.state = Utils.buildState(props);
88
}
99

1010
get getNextIndex() {
11-
return this.state.index +1;
11+
return this.state.index + 1;
1212
}
1313

1414
get getNextStartTime() {
15-
const time = Utils.convertToMs(parseFloat(Utils.removeUnit(this.state.duration)));
16-
const delay = Utils.convertToMs(parseFloat(Utils.removeUnit(this.state.delay)));
15+
const time = Utils.convertToMs(
16+
parseFloat(Utils.removeUnit(this.state.duration))
17+
);
18+
const delay = Utils.convertToMs(
19+
parseFloat(Utils.removeUnit(this.state.delay))
20+
);
1721
return time + delay;
1822
}
19-
20-
get HaveMoreAnimations() {
23+
24+
get HasMoreAnimations() {
2125
return this.getNextIndex < this.props.Animation.length;
2226
}
2327

2428
renderNextAnimate() {
25-
if (this.HaveMoreAnimations) {
29+
if (this.HasMoreAnimations) {
2630
setTimeout(() => {
27-
this.setState(
28-
Utils.buildState(this.props, this.getNextIndex),
29-
() => this.renderNextAnimate()
31+
this.setState(Utils.buildState(this.props, this.getNextIndex), () =>
32+
this.renderNextAnimate()
3033
);
3134
}, this.getNextStartTime);
35+
} else if (this.props.onAnimationDone) {
36+
setTimeout(() => {
37+
this.props.onAnimationDone();
38+
}, this.getNextStartTime);
3239
}
3340
}
3441

3542
render() {
3643
const { Animation } = this.state;
3744

38-
return (
39-
<Animation {...this.state}>
40-
{this.props.children}
41-
</Animation>
42-
);
45+
return <Animation {...this.state}>{this.props.children}</Animation>;
4346
}
4447

4548
componentDidMount() {
4649
this.renderNextAnimate();
4750
}
4851
}
4952

50-
export default StackAnimates;
53+
export default StackAnimates;

stories/Animate.stories.js

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,46 @@ import React from 'react';
22
import { storiesOf } from '@storybook/react';
33
import FullView from '../Example/FullView';
44
import Card from '../Example/Card';
5-
import Animate, {
6-
Flash,
7-
Bounce,
8-
FadeOut,
9-
FadeIn
10-
} from '../src';
11-
5+
import Animate, { Flash, Bounce, FadeOut, FadeIn } from '../src';
126

137
storiesOf('Animate (HOC)', module)
14-
.add('Multiple Animations', () => (
15-
<FullView center>
16-
<Animate Animation={[Flash, Bounce, FadeOut, FadeIn]} duration="0.8s" delay="0.2s">
17-
<Card rounded width="100px" height="100px">
18-
card content...
19-
</Card>
20-
</Animate>
21-
</FullView>
22-
))
23-
.add('Multiple Animations with diferent times and delays', () => (
24-
<FullView center>
25-
<Animate Animation={[Flash, Bounce, FadeOut, FadeIn]} duration={["0.8s", "3s", "2s", "0.4s"]} delay={["0.2s", "0.1s", "0.5s", "1s"]}>
26-
<Card rounded width="100px" height="100px">
27-
card content...
28-
</Card>
29-
</Animate>
30-
</FullView>
31-
));
8+
.add('Multiple Animations', () => (
9+
<FullView center>
10+
<Animate
11+
Animation={[Flash, Bounce, FadeOut, FadeIn]}
12+
duration="0.8s"
13+
delay="0.2s"
14+
>
15+
<Card rounded width="100px" height="100px">
16+
card content...
17+
</Card>
18+
</Animate>
19+
</FullView>
20+
))
21+
.add('Multiple Animations with diferent times and delays', () => (
22+
<FullView center>
23+
<Animate
24+
Animation={[Flash, Bounce, FadeOut, FadeIn]}
25+
duration={['0.8s', '3s', '2s', '0.4s']}
26+
delay={['0.2s', '0.1s', '0.5s', '1s']}
27+
>
28+
<Card rounded width="100px" height="100px">
29+
card content...
30+
</Card>
31+
</Animate>
32+
</FullView>
33+
))
34+
.add('with onAnimationDone callback', () => (
35+
<FullView center>
36+
<Animate
37+
Animation={[Flash, Bounce, FadeOut, FadeIn]}
38+
duration={['0.8s', '3s', '0.2s', '0.2s']}
39+
delay={['0.2s', '0.1s', '0.3s', '0.8s']}
40+
onAnimationDone={() => alert('animation finished!')}
41+
>
42+
<Card rounded width="100px" height="100px">
43+
card content...
44+
</Card>
45+
</Animate>
46+
</FullView>
47+
));

0 commit comments

Comments
 (0)