@@ -12,8 +12,7 @@ import {
12
12
findChildInChildrenByKey ,
13
13
} from './util' ;
14
14
15
- function noop ( ) {
16
- }
15
+ function noop ( ) { }
17
16
18
17
class TweenOneGroup extends Component {
19
18
static getDerivedStateFromProps ( props , { prevProps, $self } ) {
@@ -68,10 +67,12 @@ class TweenOneGroup extends Component {
68
67
delete this . isTween [ key ] ;
69
68
if ( classIsSvg ) {
70
69
tag . className . baseVal = tag . className . baseVal
71
- . replace ( this . props . animatingClassName [ isEnter ? 0 : 1 ] , '' ) . trim ( ) ;
70
+ . replace ( this . props . animatingClassName [ isEnter ? 0 : 1 ] , '' )
71
+ . trim ( ) ;
72
72
} else {
73
73
tag . className = tag . className
74
- . replace ( this . props . animatingClassName [ isEnter ? 0 : 1 ] , '' ) . trim ( ) ;
74
+ . replace ( this . props . animatingClassName [ isEnter ? 0 : 1 ] , '' )
75
+ . trim ( ) ;
75
76
}
76
77
if ( type === 'enter' ) {
77
78
this . keysToEnter . splice ( this . keysToEnter . indexOf ( key ) , 1 ) ;
@@ -88,40 +89,47 @@ class TweenOneGroup extends Component {
88
89
delete this . saveTweenTag [ $key ] ;
89
90
}
90
91
} ) ;
91
- this . setState ( {
92
- children : this . currentChildren ,
93
- } , this . reAnimQueue ) ;
92
+ this . setState (
93
+ {
94
+ children : this . currentChildren ,
95
+ } ,
96
+ this . reAnimQueue ,
97
+ ) ;
94
98
}
95
99
}
96
100
const _obj = { key, type } ;
97
101
this . props . onEnd ( _obj ) ;
98
102
}
99
- }
103
+ } ;
100
104
101
105
setClassName = ( name , isEnter ) => {
102
106
let className = name . replace ( this . props . animatingClassName [ isEnter ? 1 : 0 ] , '' ) . trim ( ) ;
103
107
if ( className . indexOf ( this . props . animatingClassName [ isEnter ? 0 : 1 ] ) === - 1 ) {
104
108
className = `${ className } ${ this . props . animatingClassName [ isEnter ? 0 : 1 ] } ` . trim ( ) ;
105
109
}
106
110
return className ;
107
- }
111
+ } ;
108
112
109
113
getTweenChild = ( child , props = { } ) => {
110
114
const key = child . key ;
111
- this . saveTweenTag [ key ] = React . createElement ( TweenOne , {
112
- ...props ,
113
- key,
114
- component : null ,
115
- } , child ) ;
115
+ this . saveTweenTag [ key ] = React . createElement (
116
+ TweenOne ,
117
+ {
118
+ ...props ,
119
+ key,
120
+ component : null ,
121
+ } ,
122
+ child ,
123
+ ) ;
116
124
return this . saveTweenTag [ key ] ;
117
- }
125
+ } ;
118
126
119
127
getCoverAnimation = ( child , i , type ) => {
120
128
let animation ;
121
129
animation = type === 'leave' ? this . props . leave : this . props . enter ;
122
130
if ( type === 'appear' ) {
123
131
const appear = transformArguments ( this . props . appear , child . key , i ) ;
124
- animation = appear && this . props . enter || null ;
132
+ animation = ( appear && this . props . enter ) || null ;
125
133
}
126
134
const animate = transformArguments ( animation , child . key , i ) ;
127
135
const onChange = this . onChange . bind ( this , animate , child . key , type ) ;
@@ -131,56 +139,62 @@ class TweenOneGroup extends Component {
131
139
onChange,
132
140
resetStyle : this . props . resetStyle ,
133
141
} ;
134
- if ( this . keysToEnter . concat ( this . keysToLeave ) . indexOf ( child . key ) >= 0
135
- || ! this . onEnterBool && animation ) {
142
+ if (
143
+ this . keysToEnter . concat ( this . keysToLeave ) . indexOf ( child . key ) >= 0 ||
144
+ ( ! this . onEnterBool && animation )
145
+ ) {
136
146
if ( ! this . saveTweenTag [ child . key ] ) {
137
147
this . isTween [ child . key ] = type ;
138
148
}
139
149
}
140
150
const children = this . getTweenChild ( child , props ) ;
141
151
return children ;
142
- }
152
+ } ;
143
153
144
154
getChildrenToRender = children => {
145
155
return children . map ( ( child , i ) => {
146
156
if ( ! child || ! child . key ) {
147
157
return child ;
148
158
}
149
159
const key = child . key ;
150
-
151
160
if ( this . keysToLeave . indexOf ( key ) >= 0 ) {
152
161
return this . getCoverAnimation ( child , i , 'leave' ) ;
153
- } else if ( ( ( this . keysToEnter . indexOf ( key ) >= 0 ) ||
154
- ( this . isTween [ key ] && this . keysToLeave . indexOf ( key ) === - 1 ) ) &&
155
- ! ( this . isTween [ key ] === 'enter' && this . saveTweenTag [ key ] ) ) {
162
+ } else if (
163
+ ( this . keysToEnter . indexOf ( key ) >= 0 ||
164
+ ( this . isTween [ key ] && this . keysToLeave . indexOf ( key ) === - 1 ) ) &&
165
+ ! ( this . isTween [ key ] === 'enter' && this . saveTweenTag [ key ] )
166
+ ) {
156
167
/**
157
- * 1. 在 key 在 enter 里。
158
- * 2. 出场未结束,触发进场, this.isTween[key] 为 leave, key 在 enter 里。
159
- * 3. 状态为 enter 且 tweenTag 里有值时,不执行重载动画属性,直接调用 tweenTag 里的。
160
- */
168
+ * 1. 在 key 在 enter 里。
169
+ * 2. 出场未结束,触发进场, this.isTween[key] 为 leave, key 在 enter 里。
170
+ * 3. 状态为 enter 且 tweenTag 里有值时,不执行重载动画属性,直接调用 tweenTag 里的。
171
+ */
161
172
return this . getCoverAnimation ( child , i , 'enter' ) ;
162
173
} else if ( ! this . onEnterBool ) {
163
174
return this . getCoverAnimation ( child , i , 'appear' ) ;
164
175
}
165
176
return this . saveTweenTag [ key ] ;
166
177
} ) ;
167
- }
178
+ } ;
168
179
169
180
reAnimQueue = ( ) => {
170
181
if ( ! Object . keys ( this . isTween ) . length && this . animQueue . length ) {
171
- const children = this . changeChildren ( this . animQueue [ this . animQueue . length - 1 ] , this . state . children ) ;
182
+ const children = this . changeChildren (
183
+ this . animQueue [ this . animQueue . length - 1 ] ,
184
+ this . state . children ,
185
+ ) ;
172
186
this . setState ( {
173
187
children,
174
188
} ) ;
175
189
this . animQueue = [ ] ;
176
190
}
177
- }
191
+ } ;
178
192
179
193
changeChildren ( nextChildren , currentChildren ) {
180
194
const newChildren = mergeChildren ( currentChildren , nextChildren ) ;
181
195
this . keysToEnter = [ ] ;
182
196
this . keysToLeave = [ ] ;
183
- nextChildren . forEach ( ( c ) => {
197
+ nextChildren . forEach ( c => {
184
198
if ( ! c ) {
185
199
return ;
186
200
}
@@ -195,7 +209,7 @@ class TweenOneGroup extends Component {
195
209
}
196
210
} ) ;
197
211
198
- currentChildren . forEach ( ( c ) => {
212
+ currentChildren . forEach ( c => {
199
213
if ( ! c ) {
200
214
return ;
201
215
}
@@ -206,31 +220,30 @@ class TweenOneGroup extends Component {
206
220
delete this . saveTweenTag [ key ] ;
207
221
}
208
222
} ) ;
209
- this . currentChildren = newChildren ;
210
223
return newChildren ;
211
224
}
212
225
213
226
render ( ) {
214
- const childrenToRender = this . getChildrenToRender ( this . state . children ) ;
215
- if ( ! this . props . component ) {
227
+ const { children } = this . state ;
228
+ // fix in strict mode https://github.com/ant-design/ant-motion/issues/323;
229
+ this . currentChildren = children ;
230
+ const childrenToRender = this . getChildrenToRender ( children ) ;
231
+ const {
232
+ component,
233
+ componentProps,
234
+ appear,
235
+ enter,
236
+ leave,
237
+ animatingClassName,
238
+ onEnd,
239
+ exclusive,
240
+ resetStyle,
241
+ ...props
242
+ } = this . props ;
243
+ if ( ! component ) {
216
244
return childrenToRender [ 0 ] || null ;
217
245
}
218
- const componentProps = { ...this . props } ;
219
- [
220
- 'component' ,
221
- 'componentProps' ,
222
- 'appear' ,
223
- 'enter' ,
224
- 'leave' ,
225
- 'animatingClassName' ,
226
- 'onEnd' ,
227
- 'exclusive' ,
228
- 'resetStyle' ,
229
- ] . forEach ( key => delete componentProps [ key ] ) ;
230
- return createElement ( this . props . component ,
231
- { ...componentProps , ...this . props . componentProps } ,
232
- childrenToRender
233
- ) ;
246
+ return createElement ( component , { ...props , ...componentProps } , childrenToRender ) ;
234
247
}
235
248
}
236
249
0 commit comments