@@ -10,7 +10,7 @@ import {
10
10
} from './utils' ;
11
11
import AnimTypes from './animTypes' ;
12
12
13
- const noop = ( ) => { } ;
13
+ const noop = ( ) => { } ;
14
14
15
15
const typeDefault = [
16
16
'displayName' ,
@@ -104,6 +104,16 @@ class QueueAnim extends React.Component {
104
104
* 进场时 deley 的 timeout 记录;
105
105
*/
106
106
this . placeholderTimeoutIds = { } ;
107
+ /**
108
+ * @param childRefs;
109
+ * 储存 children 的 ref;
110
+ */
111
+ this . childRefs = { } ;
112
+ /**
113
+ * @param currentRef;
114
+ * 记录 component 是组件时的 ref;
115
+ */
116
+ this . currentRef = null
107
117
// 第一次进入,默认进场
108
118
const children = toArrayChildren ( getChildrenFromProps ( props ) ) ;
109
119
const childrenShow = { } ;
@@ -381,6 +391,9 @@ class QueueAnim extends React.Component {
381
391
}
382
392
} ) ;
383
393
}
394
+ let ref = ( ) => {
395
+ delete this . childRefs [ key ] ;
396
+ } ;
384
397
// 处理出场
385
398
if ( i >= 0 ) {
386
399
if ( this . leaveUnfinishedChild . indexOf ( key ) >= 0 ) {
@@ -396,6 +409,9 @@ class QueueAnim extends React.Component {
396
409
} else {
397
410
// 处理进场;
398
411
i = this . keysToEnterToCallback . indexOf ( key ) ;
412
+ ref = ( c ) => {
413
+ this . childRefs [ key ] = c && c . currentRef ? c . currentRef : c ;
414
+ }
399
415
// appear=false 时,设定 childrenShow 和 tweenToEnter 都为 true, 这里不渲染 animation;
400
416
if ( this . tweenToEnter [ key ] && ! forcedReplay ) {
401
417
// 如果是已进入的,将直接返回标签。。
@@ -404,6 +420,7 @@ class QueueAnim extends React.Component {
404
420
component : child . type ,
405
421
forcedJudg,
406
422
componentProps : child . props ,
423
+ ref,
407
424
} ) ;
408
425
} else if ( ! this . tweenToEnter [ key ] ) {
409
426
animation = this . enterAnimation [ key ] || this . getTweenEnterOrLeaveData ( key , i , 0 , 'enter' ) ;
@@ -418,6 +435,7 @@ class QueueAnim extends React.Component {
418
435
forcedJudg,
419
436
componentProps : child . props ,
420
437
animation,
438
+ ref,
421
439
} ) ;
422
440
this . saveTweenOneTag [ key ] = tag ;
423
441
return tag ;
@@ -506,24 +524,28 @@ class QueueAnim extends React.Component {
506
524
} ;
507
525
508
526
render ( ) {
509
- const { ... tagProps } = this . props ;
510
- [
511
- 'component' ,
512
- 'componentProps' ,
513
- 'interval' ,
514
- 'duration' ,
515
- 'delay' ,
516
- 'type' ,
517
- 'animConfig' ,
518
- 'ease' ,
519
- 'leaveReverse' ,
520
- 'animatingClassName' ,
521
- 'forcedReplay' ,
522
- 'onEnd' ,
523
- 'appear' ,
524
- ] . forEach ( key => delete tagProps [ key ] ) ;
527
+ const {
528
+ component ,
529
+ componentProps ,
530
+ interval ,
531
+ duration ,
532
+ delay ,
533
+ type ,
534
+ animConfig ,
535
+ ease ,
536
+ leaveReverse ,
537
+ animatingClassName ,
538
+ forcedReplay ,
539
+ onEnd ,
540
+ appear ,
541
+ ... tagProps
542
+ } = this . props ;
525
543
const childrenToRender = toArrayChildren ( this . state . children ) . map ( this . getChildrenToRender ) ;
526
- const props = { ...tagProps , ...this . props . componentProps } ;
544
+ const props = {
545
+ ...tagProps ,
546
+ ...this . props . componentProps ,
547
+ ref : ( c ) => { this . currentRef = c ; }
548
+ } ;
527
549
return createElement ( this . props . component , props , childrenToRender ) ;
528
550
}
529
551
}
0 commit comments