Skip to content

Commit 0c5f878

Browse files
Adds support for a specific number of loops
1 parent a18da86 commit 0c5f878

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

lib/keyframes.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class Keyframes extends React.Component {
99
delay: PropTypes.number,
1010
loop: PropTypes.oneOfType([
1111
React.PropTypes.string,
12+
React.PropTypes.number,
1213
React.PropTypes.bool
1314
]),
1415
onStart: PropTypes.func,
@@ -18,14 +19,17 @@ export default class Keyframes extends React.Component {
1819
static defaultProps = {
1920
component: 'span',
2021
delay: 0,
21-
lopp: false,
22+
loop: 1,
2223
onStart: noop,
2324
onEnd: noop
2425
};
2526

2627
constructor (props) {
2728
super(props);
28-
this.state = { frameNum: this.props.delay ? -1 : 0 };
29+
this.state = {
30+
frameNum: this.props.delay ? -1 : 0,
31+
loopNum: 0
32+
};
2933
this.timer = null;
3034
}
3135

@@ -70,9 +74,13 @@ export default class Keyframes extends React.Component {
7074
requestNextFrame () {
7175
this.waitForDelay(() => {
7276
const frameNum = this.state.frameNum + 1;
77+
const loopNum = this.state.loopNum + 1;
7378
if (this.props.children.length <= frameNum) {
74-
if (this.props.loop === true || this.props.loop === 'infinite') {
75-
this.setState({ frameNum: 0 });
79+
if (this.props.loop === true || this.props.loop == 'infinite' || loopNum < this.props.loop) {
80+
this.setState({
81+
frameNum: 0,
82+
loopNum
83+
});
7684
} else {
7785
this.props.onEnd();
7886
return;

0 commit comments

Comments
 (0)