Skip to content

Commit a18a301

Browse files
committed
[weex] handle enter transition property fallback and warn edge cases
1 parent a0d43d3 commit a18a301

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

Diff for: src/platforms/weex/runtime/modules/transition.js

+45-6
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ function enter (_, vnode) {
7272

7373
const stylesheet = vnode.context.$options.style || {}
7474
const startState = stylesheet[startClass]
75-
const endState = stylesheet[toClass] || stylesheet[activeClass]
7675
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
7878

7979
const cb = el._enterCb = once(() => {
8080
if (cb.cancelled) {
@@ -99,7 +99,7 @@ function enter (_, vnode) {
9999
}
100100
enterHook && enterHook(el, cb)
101101

102-
if (endState) {
102+
if (needAnimation) {
103103
const animation = vnode.context._requireWeexModule('animation')
104104
animation.transition(el.ref, {
105105
styles: endState,
@@ -121,7 +121,7 @@ function enter (_, vnode) {
121121
}
122122
}
123123

124-
if (!expectsCSS && !userWantsControl) {
124+
if (!needAnimation && !userWantsControl) {
125125
cb()
126126
}
127127
}
@@ -165,7 +165,6 @@ function leave (vnode, rm) {
165165
const startState = stylesheet[leaveClass]
166166
const endState = stylesheet[leaveToClass] || stylesheet[leaveActiveClass]
167167
const transitionProperties = (stylesheet['@TRANSITION'] && stylesheet['@TRANSITION'][leaveActiveClass]) || {}
168-
const expectsCSS = startState && endState
169168

170169
const cb = el._leaveCb = once(() => {
171170
if (el.parentNode && el.parentNode._pending) {
@@ -216,7 +215,7 @@ function leave (vnode, rm) {
216215
}
217216

218217
leave && leave(el, cb)
219-
if (!expectsCSS && !userWantsControl) {
218+
if (!endState && !userWantsControl) {
220219
cb()
221220
}
222221
}
@@ -262,3 +261,43 @@ const autoCssTransition = cached(name => {
262261
appearActiveClass: `${name}-enter-active`
263262
}
264263
})
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

Comments
 (0)