@@ -25,6 +25,7 @@ class TweenOneGroup extends Component {
25
25
// 第一进入,appear 为 true 时默认用 enter 或 tween-one 上的效果
26
26
const children = toArrayChildren ( getChildrenFromProps ( this . props ) ) ;
27
27
this . originalChildren = toArrayChildren ( getChildrenFromProps ( this . props ) ) ;
28
+ this . currentChildren = toArrayChildren ( getChildrenFromProps ( this . props ) ) ;
28
29
this . state = {
29
30
children,
30
31
} ;
@@ -40,7 +41,9 @@ class TweenOneGroup extends Component {
40
41
this . animQueue . push ( nextChildren ) ;
41
42
return ;
42
43
}
43
- this . changeChildren ( nextChildren ) ;
44
+ const currentChildren = toArrayChildren ( nextProps . exclusive ?
45
+ this . originalChildren : this . state . children ) ;
46
+ this . changeChildren ( nextChildren , currentChildren ) ;
44
47
}
45
48
componentDidUpdate ( ) {
46
49
this . originalChildren = toArrayChildren ( getChildrenFromProps ( this . props ) ) ;
@@ -73,14 +76,17 @@ class TweenOneGroup extends Component {
73
76
}
74
77
} else if ( type === 'leave' ) {
75
78
this . keysToLeave . splice ( this . keysToLeave . indexOf ( key ) , 1 ) ;
76
- delete this . saveTweenTag [ key ] ;
77
- // 不需要刷新,需要控制 originalChildren.
78
- this . state . children = this . state . children . filter ( child => key !== child . key ) ;
79
+ this . currentChildren = this . currentChildren . filter ( child => key !== child . key ) ;
79
80
if ( ! this . keysToLeave . length ) {
80
- this . forceUpdate ( this . reAnimQueue ) ;
81
- /* this.setState({
82
- children: toArrayChildren(getChildrenFromProps(this.props))
83
- }, this.reAnimQueue) */
81
+ const currentChildrenKeys = this . currentChildren . map ( item => item . key ) ;
82
+ Object . keys ( this . saveTweenTag ) . forEach ( $key => {
83
+ if ( currentChildrenKeys . indexOf ( $key ) === - 1 ) {
84
+ delete this . saveTweenTag [ $key ] ;
85
+ }
86
+ } ) ;
87
+ this . setState ( {
88
+ children : this . currentChildren ,
89
+ } , this . reAnimQueue ) ;
84
90
}
85
91
}
86
92
const _obj = { key, type } ;
@@ -158,14 +164,12 @@ class TweenOneGroup extends Component {
158
164
159
165
reAnimQueue = ( ) => {
160
166
if ( ! Object . keys ( this . isTween ) . length && this . animQueue . length ) {
161
- this . originalChildren = this . state . children ;
162
- this . changeChildren ( this . animQueue [ this . animQueue . length - 1 ] ) ;
167
+ this . changeChildren ( this . animQueue [ this . animQueue . length - 1 ] , this . state . children ) ;
163
168
this . animQueue = [ ] ;
164
169
}
165
170
}
166
171
167
- changeChildren ( nextChildren ) {
168
- const currentChildren = toArrayChildren ( this . originalChildren ) ;
172
+ changeChildren ( nextChildren , currentChildren ) {
169
173
const newChildren = mergeChildren ( currentChildren , nextChildren ) ;
170
174
this . keysToEnter = [ ] ;
171
175
this . keysToLeave = [ ] ;
@@ -195,6 +199,7 @@ class TweenOneGroup extends Component {
195
199
delete this . saveTweenTag [ key ] ;
196
200
}
197
201
} ) ;
202
+ this . currentChildren = newChildren ;
198
203
this . setState ( {
199
204
children : newChildren ,
200
205
} ) ;
0 commit comments