@@ -13,7 +13,7 @@ import {
13
13
} from './utils' ;
14
14
import AnimTypes from './animTypes' ;
15
15
16
- const noop = ( ) => { } ;
16
+ const noop = ( ) => { } ;
17
17
18
18
const typeDefault = [
19
19
'displayName' ,
@@ -59,12 +59,14 @@ class QueueAnim extends React.Component {
59
59
appear : true ,
60
60
} ;
61
61
62
- static getDerivedStateFromProps ( props , { prevProps, children, childrenShow : prevChildShow , $self } ) {
62
+ static getDerivedStateFromProps (
63
+ props ,
64
+ { prevProps, children, childrenShow : prevChildShow , $self } ,
65
+ ) {
63
66
const nextState = {
64
67
prevProps : props ,
65
68
} ;
66
- if ( prevProps && props !== prevProps
67
- ) {
69
+ if ( prevProps && props !== prevProps ) {
68
70
const nextChildren = toArrayChildren ( props . children ) . filter ( c => c ) ;
69
71
let currentChildren = $self . originalChildren . filter ( item => item ) ;
70
72
if ( children . length ) {
@@ -75,8 +77,14 @@ class QueueAnim extends React.Component {
75
77
const leaveChild = children . filter (
76
78
item => item && $self . keysToLeave . indexOf ( item . key ) >= 0 ,
77
79
) ;
78
-
79
- $self . leaveUnfinishedChild = leaveChild . map ( item => item . key ) ;
80
+ $self . leaveUnfinishedChild = leaveChild
81
+ . map ( item => {
82
+ if ( $self . placeholderTimeoutIds [ item . key ] ) {
83
+ return item . key ;
84
+ }
85
+ return null ;
86
+ } )
87
+ . filter ( c => c ) ;
80
88
/**
81
89
* 获取 leaveChild 在 state.children 里的序列,再将 leaveChild 和 currentChildren 的重新排序。
82
90
* 避逸 state.children 在 leaveComplete 里没全部完成不触发,
@@ -87,7 +95,10 @@ class QueueAnim extends React.Component {
87
95
const currentChild = [ ] ;
88
96
const childReOrder = child => {
89
97
child . forEach ( item => {
90
- const order = stateChildren . indexOf ( item ) ;
98
+ const order = stateChildren . findIndex ( c => c . key === item . key ) ;
99
+ if ( currentChild . indexOf ( item ) !== - 1 ) {
100
+ return ;
101
+ }
91
102
// -1 不应该出现的情况,直接插入数组后面.
92
103
if ( order === - 1 ) {
93
104
currentChild . push ( item ) ;
@@ -175,11 +186,6 @@ class QueueAnim extends React.Component {
175
186
* 记录 TweenOne 标签,在 leaveUnfinishedChild 里使用,残留的元素不需要考虑 props 的变更。
176
187
*/
177
188
this . saveTweenOneTag = { } ;
178
- /**
179
- * @param enterAnimation;
180
- * 记录进场的动画, 在没进场完成, 将进场的动画保存,免得重新生成。
181
- */
182
- this . enterAnimation = { } ;
183
189
/**
184
190
* @param childrenShow;
185
191
* 记录 animation 里是否需要 startAnim;
@@ -216,7 +222,7 @@ class QueueAnim extends React.Component {
216
222
* @param currentRef;
217
223
* 记录 component 是组件时的 ref;
218
224
*/
219
- this . currentRef = null
225
+ this . currentRef = null ;
220
226
// 第一次进入,默认进场
221
227
const children = toArrayChildren ( getChildrenFromProps ( props ) ) ;
222
228
const childrenShow = { } ;
@@ -295,8 +301,8 @@ class QueueAnim extends React.Component {
295
301
const end = type === 'enter' ? 0 : 1 ;
296
302
const animate = this . getAnimData ( props , key , i , enterOrLeave , end ) ;
297
303
const startAnim =
298
- type === 'enter' && ( props . forcedReplay || ! this . childrenShow [ key ] ) ?
299
- this . getAnimData ( props , key , i , enterOrLeave , start )
304
+ type === 'enter' && ( props . forcedReplay || ! this . childrenShow [ key ] )
305
+ ? this . getAnimData ( props , key , i , enterOrLeave , start )
300
306
: null ;
301
307
let ease = transformArguments ( props . ease , key , i ) [ enterOrLeave ] ;
302
308
const duration = transformArguments ( props . duration , key , i ) [ enterOrLeave ] ;
@@ -372,10 +378,10 @@ class QueueAnim extends React.Component {
372
378
*/
373
379
return props . animConfig
374
380
? this . getTweenAnimConfig (
375
- transformArguments ( props . animConfig , key , i ) [ enterOrLeave ] ,
376
- startOrEnd ,
377
- enterOrLeave ,
378
- )
381
+ transformArguments ( props . animConfig , key , i ) [ enterOrLeave ] ,
382
+ startOrEnd ,
383
+ enterOrLeave ,
384
+ )
379
385
: this . getTweenType ( transformArguments ( props . type , key , i ) [ enterOrLeave ] , startOrEnd ) ;
380
386
} ;
381
387
@@ -417,9 +423,9 @@ class QueueAnim extends React.Component {
417
423
} else {
418
424
// 处理进场;
419
425
i = toArrayChildren ( children ) . findIndex ( c => c && c . key === key ) ;
420
- ref = ( c ) => {
426
+ ref = c => {
421
427
this . childRefs [ key ] = c && c . currentRef ? c . currentRef : c ;
422
- }
428
+ } ;
423
429
// appear=false 时,设定 childrenShow 和 tweenToEnter 都为 true, 这里不渲染 animation;
424
430
if ( this . tweenToEnter [ key ] && ! forcedReplay ) {
425
431
// 如果是已进入的,将直接返回标签。。
@@ -430,9 +436,9 @@ class QueueAnim extends React.Component {
430
436
componentProps : child . props ,
431
437
ref,
432
438
} ) ;
433
- } else if ( ! this . tweenToEnter [ key ] ) {
434
- animation = this . enterAnimation [ key ] || this . getTweenEnterOrLeaveData ( key , i , 0 , 'enter' ) ;
435
- this . enterAnimation [ key ] = animation ;
439
+ }
440
+ if ( ! this . tweenToEnter [ key ] || forcedReplay ) {
441
+ animation = this . getTweenEnterOrLeaveData ( key , i , 0 , 'enter' ) ;
436
442
}
437
443
}
438
444
const paused = this . keysToEnterPaused [ key ] && this . keysToLeave . indexOf ( key ) === - 1 ;
@@ -483,7 +489,7 @@ class QueueAnim extends React.Component {
483
489
elem . className = `${ elem . className } ${ animatingClassName [ 0 ] } ` . trim ( ) ;
484
490
}
485
491
this . childrenShow [ key ] = true ;
486
- }
492
+ } ;
487
493
488
494
enterComplete = ( key , e ) => {
489
495
if ( this . keysToEnterPaused [ key ] || this . keysToLeave . indexOf ( key ) >= 0 ) {
@@ -492,7 +498,6 @@ class QueueAnim extends React.Component {
492
498
const elem = e . target ;
493
499
elem . className = elem . className . replace ( this . props . animatingClassName [ 0 ] , '' ) . trim ( ) ;
494
500
this . tweenToEnter [ key ] = true ;
495
- delete this . enterAnimation [ key ] ;
496
501
this . props . onEnd ( { key, type : 'enter' , target : elem } ) ;
497
502
} ;
498
503
@@ -555,7 +560,9 @@ class QueueAnim extends React.Component {
555
560
const props = {
556
561
...tagProps ,
557
562
...this . props . componentProps ,
558
- ref : ( c ) => { this . currentRef = c ; }
563
+ ref : c => {
564
+ this . currentRef = c ;
565
+ } ,
559
566
} ;
560
567
return createElement ( this . props . component , props , childrenToRender ) ;
561
568
}
0 commit comments