@@ -53,10 +53,9 @@ class QueueAnim extends React.Component {
5353 constructor ( props ) {
5454 super ( props ) ;
5555 this . oneEnter = false ;
56- this . tweenKeyType = { } ;
56+ this . tweenToShow = { } ;
5757 this . keysToEnter = [ ] ;
5858 this . keysToLeave = [ ] ;
59- this . saveTweenAnim = { } ;
6059 this . keysToEnterPaused = { } ;
6160 this . placeholderTimeoutIds = { } ;
6261 // 第一次进入,默认进场
@@ -196,11 +195,7 @@ class QueueAnim extends React.Component {
196195 const end = type === 'enter' ? 0 : 1 ;
197196 let startAnim = this . getAnimData ( props , key , i , enterOrLeave , start ) ;
198197 const animate = this . getAnimData ( props , key , i , enterOrLeave , end ) ;
199- /**
200- * 如果 this.tweenKeyType[key] 为空时,为第一次触发,需要设置开始。
201- * 如果 this.tweenKeyType[key] 有值时,说明正在动画,此时切换不需要开始。
202- */
203- startAnim = props . enterForcedRePlay || ! this . tweenKeyType [ key ] || ! this . saveTweenAnim [ key ] ?
198+ startAnim = ( type === 'enter' && props . enterForcedRePlay ) || ! this . tweenToShow [ key ] ?
204199 startAnim : { } ;
205200 let ease = transformArguments ( props . ease , key , i ) [ enterOrLeave ] ;
206201 const duration = transformArguments ( props . duration , key , i ) [ enterOrLeave ] ;
@@ -278,48 +273,40 @@ class QueueAnim extends React.Component {
278273 return child ;
279274 }
280275 const key = child . key ;
276+ if ( ! this . state . childrenShow [ key ] ) {
277+ return null ;
278+ }
281279 let i = this . keysToLeave . indexOf ( key ) ;
282- if ( ( i >= 0 && this . state . childrenShow [ key ] )
283- || this . state . childrenShow [ key ] ) {
284- let animation ;
285- if ( i >= 0 ) {
286- if ( this . tweenKeyType [ key ] === 'leave' && this . saveTweenAnim [ key ] ) {
287- animation = this . saveTweenAnim [ key ] ;
288- } else {
289- const interval = transformArguments ( this . props . interval , key , i ) [ 1 ] ;
290- let delay = transformArguments ( this . props . delay , key , i ) [ 1 ] ;
291- const order = this . props . leaveReverse ? ( this . keysToLeave . length - i - 1 ) : i ;
292- delay = interval * order + delay ;
293- animation = this . getTweenEnterOrLeaveData ( key , i , delay , 'leave' ) ;
294- this . saveTweenAnim [ key ] = animation ;
295- }
280+ let animation ;
281+ // 处理出场
282+ if ( i >= 0 ) {
283+ const interval = transformArguments ( this . props . interval , key , i ) [ 1 ] ;
284+ let delay = transformArguments ( this . props . delay , key , i ) [ 1 ] ;
285+ const order = this . props . leaveReverse ? ( this . keysToLeave . length - i - 1 ) : i ;
286+ delay = interval * order + delay ;
287+ animation = this . getTweenEnterOrLeaveData ( key , i , delay , 'leave' ) ;
288+ } else {
289+ // 处理进场;
290+ i = this . keysToEnterToCallback . indexOf ( key ) ;
291+ if ( ! this . oneEnter && ! this . props . appear ) {
292+ animation = this . getTweenAppearData ( key , i ) ;
296293 } else {
297- i = this . keysToEnterToCallback . indexOf ( key ) ;
298- if ( ! this . oneEnter && ! this . props . appear ) {
299- animation = this . getTweenAppearData ( key , i ) ;
300- } else if ( this . tweenKeyType [ key ] === 'enter' && this . saveTweenAnim [ key ] ) {
301- animation = this . saveTweenAnim [ key ] ;
302- } else {
303- animation = this . getTweenEnterOrLeaveData ( key , i , 0 , 'enter' ) ;
304- this . saveTweenAnim [ key ] = animation ;
305- }
294+ animation = this . getTweenEnterOrLeaveData ( key , i , 0 , 'enter' ) ;
306295 }
307- const paused = this . keysToEnterPaused [ key ]
308- && ! ( this . keysToLeave . indexOf ( key ) >= 0 && this . state . childrenShow [ key ] ) ;
309- animation = paused ? null : animation ;
310- const isFunc = typeof child . type === 'function' ;
311- const forcedJudg = isFunc ? { } : null ;
312- if ( isFunc ) {
313- Object . keys ( child . type ) . forEach ( name => {
314- if ( typeDefault . indexOf ( name ) === - 1 ) {
315- forcedJudg [ name ] = child . type [ name ] ;
316- }
317- } ) ;
318- }
319- return createElement ( TweenOne ,
320- { key, component : child . type , componentProps : child . props , forcedJudg, animation } ) ;
321296 }
322- return null ;
297+ const paused = this . keysToEnterPaused [ key ] && ! this . keysToLeave . indexOf ( key ) >= 0 ;
298+ animation = paused ? null : animation ;
299+ const isFunc = typeof child . type === 'function' ;
300+ const forcedJudg = isFunc ? { } : null ;
301+ if ( isFunc ) {
302+ Object . keys ( child . type ) . forEach ( name => {
303+ if ( typeDefault . indexOf ( name ) === - 1 ) {
304+ forcedJudg [ name ] = child . type [ name ] ;
305+ }
306+ } ) ;
307+ }
308+ return createElement ( TweenOne ,
309+ { key, component : child . type , componentProps : child . props , forcedJudg, animation } ) ;
323310 } ;
324311
325312 performEnter = ( key , i ) => {
@@ -332,7 +319,6 @@ class QueueAnim extends React.Component {
332319 if ( this . keysToEnter . indexOf ( key ) >= 0 ) {
333320 this . keysToEnter . splice ( this . keysToEnter . indexOf ( key ) , 1 ) ;
334321 }
335- this . tweenKeyType [ key ] = 'enter' ;
336322 }
337323
338324 performEnterBegin = ( key ) => {
@@ -347,34 +333,33 @@ class QueueAnim extends React.Component {
347333 performLeave = ( key ) => {
348334 ticker . clear ( this . placeholderTimeoutIds [ key ] ) ;
349335 delete this . placeholderTimeoutIds [ key ] ;
350- this . tweenKeyType [ key ] = 'leave' ;
351336 }
352337
353338 enterBegin = ( key , e ) => {
354339 const elem = e . target ;
355340 const animatingClassName = this . props . animatingClassName ;
356341 elem . className = elem . className . replace ( animatingClassName [ 1 ] , '' ) ;
357342 if ( elem . className . indexOf ( animatingClassName [ 0 ] ) === - 1 ) {
358- elem . className + = ( `${ elem . className ? ' ' : '' } ${ animatingClassName [ 0 ] } ` ) ;
343+ elem . className = ( `${ elem . className } ${ animatingClassName [ 0 ] } ` ) . trim ( ) ;
359344 }
345+ this . tweenToShow [ key ] = true ;
360346 }
361347
362348 enterComplete = ( key , e ) => {
363- if ( this . keysToEnterPaused [ key ] ) {
349+ if ( this . keysToEnterPaused [ key ] || this . keysToLeave . indexOf ( key ) >= 0 ) {
364350 return ;
365351 }
366352 const elem = e . target ;
367353 elem . className = elem . className . replace ( this . props . animatingClassName [ 0 ] , '' ) . trim ( ) ;
368354 this . props . onEnd ( { key, type : 'enter' } ) ;
369- delete this . tweenKeyType [ key ] ;
370355 }
371356
372357 leaveBegin = ( key , e ) => {
373358 const elem = e . target ;
374359 const animatingClassName = this . props . animatingClassName ;
375360 elem . className = elem . className . replace ( animatingClassName [ 0 ] , '' ) ;
376361 if ( elem . className . indexOf ( animatingClassName [ 1 ] ) === - 1 ) {
377- elem . className + = ( ` ${ animatingClassName [ 1 ] } ` ) ;
362+ elem . className = ( `${ elem . className } ${ animatingClassName [ 1 ] } ` ) . trim ( ) ;
378363 }
379364 }
380365
@@ -387,8 +372,7 @@ class QueueAnim extends React.Component {
387372 delete childrenShow [ key ] ;
388373 if ( this . keysToLeave . indexOf ( key ) >= 0 ) {
389374 this . keysToLeave . splice ( this . keysToLeave . indexOf ( key ) , 1 ) ;
390- delete this . saveTweenAnim [ key ] ;
391- delete this . tweenKeyType [ key ] ;
375+ delete this . tweenToShow [ key ] ;
392376 }
393377 const needLeave = this . keysToLeave . some ( c => childrenShow [ c ] ) ;
394378 if ( ! needLeave ) {
0 commit comments