Skip to content

Commit d8de122

Browse files
committed
add callback when animation start and end
1 parent df612aa commit d8de122

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/QueueAnim.jsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class QueueAnim extends React.Component {
349349
delay: interval * order + delay,
350350
duration,
351351
easing: this.getVelocityEasing(key, i)[1],
352-
begin: this.leaveBegin.bind(this),
352+
begin: this.leaveBegin.bind(this, key),
353353
complete: this.leaveComplete.bind(this, key),
354354
});
355355
}
@@ -362,6 +362,9 @@ class QueueAnim extends React.Component {
362362
elem.className += (` ${animatingClassName[0]}`);
363363
}
364364
});
365+
if (this.props.onStart) {
366+
this.props.onStart({ key, type: 'enter' });
367+
}
365368
}
366369

367370
enterComplete(key, elements) {
@@ -371,16 +374,22 @@ class QueueAnim extends React.Component {
371374
elements.forEach((elem) => {
372375
elem.className = elem.className.replace(this.props.animatingClassName[0], '').trim();
373376
});
377+
if (this.props.onEnd) {
378+
this.props.onEnd({ key, type: 'enter' });
379+
}
374380
}
375381

376-
leaveBegin(elements) {
382+
leaveBegin(key, elements) {
377383
elements.forEach((elem) => {
378384
const animatingClassName = this.props.animatingClassName;
379385
elem.className = elem.className.replace(animatingClassName[0], '');
380386
if (elem.className.indexOf(animatingClassName[1]) === -1) {
381387
elem.className += (` ${animatingClassName[1]}`);
382388
}
383389
});
390+
if (this.props.onStart) {
391+
this.props.onStart({ key, type: 'leave' });
392+
}
384393
}
385394

386395
leaveComplete(key, elements) {
@@ -404,6 +413,9 @@ class QueueAnim extends React.Component {
404413
elements.forEach((elem) => {
405414
elem.className = elem.className.replace(this.props.animatingClassName[1], '').trim();
406415
});
416+
if (this.props.onEnd) {
417+
this.props.onEnd({ key, type: 'leave' });
418+
}
407419
}
408420

409421
render() {
@@ -431,6 +443,8 @@ class QueueAnim extends React.Component {
431443
'leaveReverse',
432444
'animatingClassName',
433445
'enterForcedRePlay',
446+
'onStart',
447+
'onEnd',
434448
].forEach(key => delete tagProps[key]);
435449
return createElement(this.props.component, { ...tagProps }, childrenToRender);
436450
}
@@ -455,6 +469,8 @@ QueueAnim.propTypes = {
455469
leaveReverse: React.PropTypes.bool,
456470
enterForcedRePlay: React.PropTypes.bool,
457471
animatingClassName: React.PropTypes.array,
472+
onStart: React.PropTypes.func,
473+
onEnd: React.PropTypes.func,
458474
};
459475

460476
QueueAnim.defaultProps = {

0 commit comments

Comments
 (0)