@@ -56,11 +56,6 @@ class QueueAnim extends React.Component {
56
56
} ;
57
57
constructor ( props ) {
58
58
super ( props ) ;
59
- /**
60
- * @param oneEnter
61
- * 记录第一次进入;
62
- */
63
- this . oneEnter = false ;
64
59
/**
65
60
* @param tweenToEnter;
66
61
* 记录强制切换时是否需要添加 animation;
@@ -77,6 +72,11 @@ class QueueAnim extends React.Component {
77
72
* 记录 TweenOne 标签,在 leaveUnfinishedChild 里使用,残留的元素不需要考虑 props 的变更。
78
73
*/
79
74
this . saveTweenOneTag = { } ;
75
+ /**
76
+ * @param enterAnimation;
77
+ * 记录进场的动画, 在没进场完成, 将进场的动画保存,免得重新生成。
78
+ */
79
+ this . enterAnimation = { } ;
80
80
/**
81
81
* @param childrenShow;
82
82
* 记录 animation 里是否需要 startAnim;
@@ -115,6 +115,7 @@ class QueueAnim extends React.Component {
115
115
this . keysToEnter . push ( child . key ) ;
116
116
} else {
117
117
childrenShow [ child . key ] = true ;
118
+ this . tweenToEnter [ child . key ] = true ;
118
119
}
119
120
} ) ;
120
121
this . keysToEnterToCallback = [ ...this . keysToEnter ] ;
@@ -129,7 +130,6 @@ class QueueAnim extends React.Component {
129
130
if ( this . props . appear ) {
130
131
this . componentDidUpdate ( ) ;
131
132
}
132
- this . oneEnter = true ;
133
133
}
134
134
135
135
componentWillReceiveProps ( nextProps ) {
@@ -275,10 +275,11 @@ class QueueAnim extends React.Component {
275
275
const enterOrLeave = type === 'enter' ? 0 : 1 ;
276
276
const start = type === 'enter' ? 1 : 0 ;
277
277
const end = type === 'enter' ? 0 : 1 ;
278
- let startAnim = this . getAnimData ( props , key , i , enterOrLeave , start ) ;
279
278
const animate = this . getAnimData ( props , key , i , enterOrLeave , end ) ;
280
- startAnim =
281
- type === 'enter' && ( props . forcedReplay || ! this . childrenShow [ key ] ) ? startAnim : null ;
279
+ const startAnim =
280
+ type === 'enter' && ( props . forcedReplay || ! this . childrenShow [ key ] ) ?
281
+ this . getAnimData ( props , key , i , enterOrLeave , start )
282
+ : null ;
282
283
let ease = transformArguments ( props . ease , key , i ) [ enterOrLeave ] ;
283
284
const duration = transformArguments ( props . duration , key , i ) [ enterOrLeave ] ;
284
285
if ( Array . isArray ( ease ) ) {
@@ -345,11 +346,6 @@ class QueueAnim extends React.Component {
345
346
return [ animateData . startAnimate , animateData . animation ] . filter ( item => item ) ;
346
347
} ;
347
348
348
- getTweenAppearData = ( key , i ) => ( {
349
- ...this . getAnimData ( this . props , key , i , 0 , 0 ) ,
350
- duration : 0 ,
351
- } ) ;
352
-
353
349
getAnimData = ( props , key , i , enterOrLeave , startOrEnd ) => {
354
350
/**
355
351
* transformArguments 第一个为 enter, 第二个为 leave;
@@ -358,15 +354,15 @@ class QueueAnim extends React.Component {
358
354
*/
359
355
return props . animConfig
360
356
? this . getTweenAnimConfig (
361
- transformArguments ( props . animConfig , key , i ) [ enterOrLeave ] ,
362
- startOrEnd ,
363
- enterOrLeave ,
364
- )
357
+ transformArguments ( props . animConfig , key , i ) [ enterOrLeave ] ,
358
+ startOrEnd ,
359
+ enterOrLeave ,
360
+ )
365
361
: this . getTweenType ( transformArguments ( props . type , key , i ) [ enterOrLeave ] , startOrEnd ) ;
366
362
} ;
367
363
368
364
getChildrenToRender = child => {
369
- const { forcedReplay, leaveReverse, appear , delay, interval } = this . props ;
365
+ const { forcedReplay, leaveReverse, delay, interval } = this . props ;
370
366
if ( ! child || ! child . key ) {
371
367
return child ;
372
368
}
@@ -400,11 +396,7 @@ class QueueAnim extends React.Component {
400
396
} else {
401
397
// 处理进场;
402
398
i = this . keysToEnterToCallback . indexOf ( key ) ;
403
- if ( ! this . oneEnter && ! appear ) {
404
- animation = this . getTweenAppearData ( key , i ) ;
405
- } else {
406
- animation = this . getTweenEnterOrLeaveData ( key , i , 0 , 'enter' ) ;
407
- }
399
+ // appear=false 时,设定 childrenShow 和 tweenToEnter 都为 true, 这里不渲染 animation;
408
400
if ( this . tweenToEnter [ key ] && ! forcedReplay ) {
409
401
// 如果是已进入的,将直接返回标签。。
410
402
return createElement ( TweenOne , {
@@ -413,6 +405,9 @@ class QueueAnim extends React.Component {
413
405
forcedJudg,
414
406
componentProps : child . props ,
415
407
} ) ;
408
+ } else if ( ! this . tweenToEnter [ key ] ) {
409
+ animation = this . enterAnimation [ key ] || this . getTweenEnterOrLeaveData ( key , i , 0 , 'enter' ) ;
410
+ this . enterAnimation [ key ] = animation ;
416
411
}
417
412
}
418
413
const paused = this . keysToEnterPaused [ key ] && this . keysToLeave . indexOf ( key ) === - 1 ;
@@ -471,6 +466,7 @@ class QueueAnim extends React.Component {
471
466
const elem = e . target ;
472
467
elem . className = elem . className . replace ( this . props . animatingClassName [ 0 ] , '' ) . trim ( ) ;
473
468
this . tweenToEnter [ key ] = true ;
469
+ delete this . enterAnimation [ key ] ;
474
470
this . props . onEnd ( { key, type : 'enter' , target : elem } ) ;
475
471
} ;
476
472
0 commit comments