@@ -72,9 +72,9 @@ function enter (_, vnode) {
72
72
73
73
const stylesheet = vnode . context . $options . style || { }
74
74
const startState = stylesheet [ startClass ]
75
- const endState = stylesheet [ toClass ] || stylesheet [ activeClass ]
76
75
const transitionProperties = ( stylesheet [ '@TRANSITION' ] && stylesheet [ '@TRANSITION' ] [ activeClass ] ) || { }
77
- const expectsCSS = startState && endState
76
+ const endState = getEnterTargetState ( el , stylesheet , startClass , toClass , activeClass , vnode . context )
77
+ const needAnimation = Object . keys ( endState ) . length > 0
78
78
79
79
const cb = el . _enterCb = once ( ( ) => {
80
80
if ( cb . cancelled ) {
@@ -99,7 +99,7 @@ function enter (_, vnode) {
99
99
}
100
100
enterHook && enterHook ( el , cb )
101
101
102
- if ( endState ) {
102
+ if ( needAnimation ) {
103
103
const animation = vnode . context . _requireWeexModule ( 'animation' )
104
104
animation . transition ( el . ref , {
105
105
styles : endState ,
@@ -121,7 +121,7 @@ function enter (_, vnode) {
121
121
}
122
122
}
123
123
124
- if ( ! expectsCSS && ! userWantsControl ) {
124
+ if ( ! needAnimation && ! userWantsControl ) {
125
125
cb ( )
126
126
}
127
127
}
@@ -165,7 +165,6 @@ function leave (vnode, rm) {
165
165
const startState = stylesheet [ leaveClass ]
166
166
const endState = stylesheet [ leaveToClass ] || stylesheet [ leaveActiveClass ]
167
167
const transitionProperties = ( stylesheet [ '@TRANSITION' ] && stylesheet [ '@TRANSITION' ] [ leaveActiveClass ] ) || { }
168
- const expectsCSS = startState && endState
169
168
170
169
const cb = el . _leaveCb = once ( ( ) => {
171
170
if ( el . parentNode && el . parentNode . _pending ) {
@@ -216,7 +215,7 @@ function leave (vnode, rm) {
216
215
}
217
216
218
217
leave && leave ( el , cb )
219
- if ( ! expectsCSS && ! userWantsControl ) {
218
+ if ( ! endState && ! userWantsControl ) {
220
219
cb ( )
221
220
}
222
221
}
@@ -262,3 +261,43 @@ const autoCssTransition = cached(name => {
262
261
appearActiveClass : `${ name } -enter-active`
263
262
}
264
263
} )
264
+
265
+ // determine the target animation style for an entering transition.
266
+ function getEnterTargetState ( el , stylesheet , startClass , endClass , activeClass , vm ) {
267
+ const targetState = { }
268
+ const startState = stylesheet [ startClass ]
269
+ const endState = stylesheet [ endClass ]
270
+ const activeState = stylesheet [ activeClass ]
271
+ // 1. fallback to element's default styling
272
+ if ( startState ) {
273
+ for ( const key in startState ) {
274
+ targetState [ key ] = el . style [ key ]
275
+ if (
276
+ targetState [ key ] == null &&
277
+ ( ! activeState || activeState [ key ] == null ) &&
278
+ ( ! endState || endState [ key ] == null )
279
+ ) {
280
+ console . log (
281
+ `transition property "${ key } " is declared in enter starting class (.${ startClass } ), ` +
282
+ `but not declared anywhere in enter ending class (.${ endClass } ), ` +
283
+ `enter active cass (.${ activeClass } ) or the element's default styling. ` +
284
+ `Note in Weex, CSS properties need explicit values to be transitionable.`
285
+ )
286
+ }
287
+ }
288
+ }
289
+ // 2. if state is mixed in active state, extract them while excluding
290
+ // transition properties
291
+ if ( activeState ) {
292
+ for ( const key in activeState ) {
293
+ if ( key . indexOf ( 'transition' ) !== 0 ) {
294
+ targetState [ key ] = activeState [ key ]
295
+ }
296
+ }
297
+ }
298
+ // 3. explicit endState has highest priority
299
+ if ( endState ) {
300
+ extend ( targetState , endState )
301
+ }
302
+ return targetState
303
+ }
0 commit comments