diff --git a/src/platforms/weex/runtime/modules/attrs.js b/src/platforms/weex/runtime/modules/attrs.js index 39d532d84d7..1b6185cae70 100755 --- a/src/platforms/weex/runtime/modules/attrs.js +++ b/src/platforms/weex/runtime/modules/attrs.js @@ -15,18 +15,27 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { attrs = vnode.data.attrs = extend({}, attrs) } + const supportBatchUpdate = typeof elm.setAttrs === 'function' + const batchedAttrs = {} for (key in attrs) { cur = attrs[key] old = oldAttrs[key] if (old !== cur) { - elm.setAttr(key, cur) + supportBatchUpdate + ? (batchedAttrs[key] = cur) + : elm.setAttr(key, cur) } } for (key in oldAttrs) { if (attrs[key] == null) { - elm.setAttr(key) + supportBatchUpdate + ? (batchedAttrs[key] = undefined) + : elm.setAttr(key) } } + if (supportBatchUpdate) { + elm.setAttrs(batchedAttrs) + } } export default { diff --git a/src/platforms/weex/runtime/modules/class.js b/src/platforms/weex/runtime/modules/class.js index b1e3b188561..8d9d51ec603 100755 --- a/src/platforms/weex/runtime/modules/class.js +++ b/src/platforms/weex/runtime/modules/class.js @@ -36,8 +36,12 @@ function updateClass (oldVnode: VNodeWithData, vnode: VNodeWithData) { } const style = getStyle(oldClassList, classList, ctx) - for (const key in style) { - el.setStyle(key, style[key]) + if (typeof el.setStyles === 'function') { + el.setStyles(style) + } else { + for (const key in style) { + el.setStyle(key, style[key]) + } } } diff --git a/src/platforms/weex/runtime/modules/style.js b/src/platforms/weex/runtime/modules/style.js index 9c60fd1aaa4..bdabd17b7a9 100755 --- a/src/platforms/weex/runtime/modules/style.js +++ b/src/platforms/weex/runtime/modules/style.js @@ -11,11 +11,18 @@ function createStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) { } const elm = vnode.elm const staticStyle = vnode.data.staticStyle + const supportBatchUpdate = typeof elm.setStyles === 'function' + const batchedStyles = {} for (const name in staticStyle) { if (staticStyle[name]) { - elm.setStyle(normalize(name), staticStyle[name]) + supportBatchUpdate + ? (batchedStyles[normalize(name)] = staticStyle[name]) + : elm.setStyle(normalize(name), staticStyle[name]) } } + if (supportBatchUpdate) { + elm.setStyles(batchedStyles) + } updateStyle(oldVnode, vnode) } @@ -41,14 +48,23 @@ function updateStyle (oldVnode: VNodeWithData, vnode: VNodeWithData) { style = vnode.data.style = extend({}, style) } + const supportBatchUpdate = typeof elm.setStyles === 'function' + const batchedStyles = {} for (name in oldStyle) { if (!style[name]) { - elm.setStyle(normalize(name), '') + supportBatchUpdate + ? (batchedStyles[normalize(name)] = '') + : elm.setStyle(normalize(name), '') } } for (name in style) { cur = style[name] - elm.setStyle(normalize(name), cur) + supportBatchUpdate + ? (batchedStyles[normalize(name)] = cur) + : elm.setStyle(normalize(name), cur) + } + if (supportBatchUpdate) { + elm.setStyles(batchedStyles) } } diff --git a/src/platforms/weex/runtime/modules/transition.js b/src/platforms/weex/runtime/modules/transition.js index 86e3f6d9941..e474c2b3e9b 100644 --- a/src/platforms/weex/runtime/modules/transition.js +++ b/src/platforms/weex/runtime/modules/transition.js @@ -119,8 +119,12 @@ function enter (_, vnode) { beforeEnterHook && beforeEnterHook(el) if (startState) { - for (const key in startState) { - el.setStyle(key, startState[key]) + if (typeof el.setStyles === 'function') { + el.setStyles(startState) + } else { + for (const key in startState) { + el.setStyle(key, startState[key]) + } } }