From e917d80a4b523432c061afd98ee558b5e85465f4 Mon Sep 17 00:00:00 2001 From: luciolong Date: Mon, 6 Aug 2018 17:37:59 +0800 Subject: [PATCH 01/13] [Android]prerender merge --- .../java/com/taobao/weex/WXSDKInstance.java | 38 +- .../weex/prerender/PreRenderContext.java | 48 ++ .../weex/prerender/WXPrerenderManager.java | 64 +++ .../com/taobao/weex/ui/WXRenderManager.java | 18 + .../weex/ui/action/ActionInvokeMethod.java | 9 +- .../weex/ui/action/BasicComponentData.java | 29 ++ .../GraphicActionAbstractAddElement.java | 27 +- .../ui/action/GraphicActionAddElement.java | 20 +- .../weex/ui/action/GraphicActionAddEvent.java | 12 +- .../ui/action/GraphicActionAnimation.java | 2 +- .../ui/action/GraphicActionCreateBody.java | 6 + .../ui/action/GraphicActionCreateFinish.java | 6 +- .../weex/ui/action/GraphicActionLayout.java | 13 +- .../ui/action/GraphicActionMoveElement.java | 8 +- .../ui/action/GraphicActionRemoveElement.java | 6 + .../ui/action/GraphicActionRemoveEvent.java | 13 +- .../action/GraphicActionScrollToElement.java | 15 +- .../ui/action/GraphicActionTransformNode.java | 42 ++ .../ui/action/GraphicActionUpdateAttr.java | 18 +- .../ui/action/GraphicActionUpdateStyle.java | 75 ++- .../ui/component/node/WXComponentNode.java | 451 ++++++++++++++++++ .../node/WXComponentNodeBuilder.java | 85 ++++ 22 files changed, 907 insertions(+), 98 deletions(-) create mode 100644 android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNodeBuilder.java diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java index 36ca0bb56d..25e86dbca9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java @@ -67,11 +67,14 @@ import com.taobao.weex.instance.InstanceOnFireEventInterceptor; import com.taobao.weex.layout.ContentBoxMeasurement; import com.taobao.weex.performance.WXInstanceApm; +import com.taobao.weex.performance.WXAnalyzerDataTransfer; +import com.taobao.weex.prerender.PreRenderContext; import com.taobao.weex.tracing.WXTracing; import com.taobao.weex.ui.action.GraphicActionAddElement; import com.taobao.weex.ui.component.NestedContainer; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXEmbed; +import com.taobao.weex.ui.component.node.WXComponentNode; import com.taobao.weex.ui.flat.FlatGUIContext; import com.taobao.weex.ui.view.WXScrollView; import com.taobao.weex.utils.Trace; @@ -139,10 +142,6 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan private @NonNull FlatGUIContext mFlatGUIContext =new FlatGUIContext(); - private Map mContainerInfo; - - public boolean isNewFsEnd = false; - /** * bundle type */ @@ -264,6 +263,37 @@ public void setUseSingleProcess(boolean flag) { WXBridgeManager.getInstance().setUseSingleProcess(flag); } + public void preRender(String pageName, final String url, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + if (mPrerenderContext.interceptRenderState.compareAndSet(PreRenderContext.INTERCEPT_RENDER_CLOSE, PreRenderContext.INTERCEPT_RENDER_OPEN)) { + mPrerenderContext.width = width; + mPrerenderContext.height = height; + renderByUrl(pageName, url, options, jsonInitData, flag); + } + } + + public void realRender(@NonNull Context context) { + if (mPrerenderContext.interceptRenderState.compareAndSet(PreRenderContext.INTERCEPT_RENDER_OPEN, PreRenderContext.INTERCEPT_RENDER_CLOSE)) { + mContext = context; + WXComponentNode rootNode = mPrerenderContext.rootNode; + if (rootNode != null) { + mPrerenderContext.rootNode.startTransform(); + } + } + } + + @NonNull + public PreRenderContext getPrerenderContext() { + return mPrerenderContext; + } + + public Map getNodeMap() { + return mPrerenderContext.nodeMap; + } + + public boolean getNeedInterceptRender() { + return mPrerenderContext.interceptRenderState.get() == PreRenderContext.INTERCEPT_RENDER_OPEN; + } + /** * set open SandBox * @param flag diff --git a/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java b/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java new file mode 100644 index 0000000000..70de0e0996 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.prerender; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.taobao.weex.ui.component.node.WXComponentNode; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Created by luciolong on 18/07/2018. + */ +public class PreRenderContext { + public static final int INTERCEPT_RENDER_CLOSE = 0; + public static final int INTERCEPT_RENDER_OPEN = 1; + + // need intercept real render + public AtomicInteger interceptRenderState = new AtomicInteger(INTERCEPT_RENDER_CLOSE); + + @Nullable + public WXComponentNode rootNode; + + @NonNull + public Map nodeMap = new HashMap<>(); + + public int width = 0; + public int height = 0; +} diff --git a/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java b/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java new file mode 100644 index 0000000000..5302e9d125 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.prerender; + +import android.content.Context; +import android.support.annotation.Nullable; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.common.WXRenderStrategy; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Created by luciolong on 03/08/2018. + */ +public class WXPrerenderManager { + private volatile ConcurrentHashMap mPreloadInstanceMap = new ConcurrentHashMap<>(); + + private static class SingletonHolder { + private static final WXPrerenderManager INSTANCE = new WXPrerenderManager(); + } + + public static WXPrerenderManager getInstance() { + return SingletonHolder.INSTANCE; + } + + private WXPrerenderManager() { + } + + public WXSDKInstance preload(String pageName, final String url, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + if (!mPreloadInstanceMap.containsKey(url)) { + WXSDKInstance instance = new WXSDKInstance(null); + instance.preRender(pageName, url, options, jsonInitData, width, height, flag); + mPreloadInstanceMap.put(url, instance); + return instance; + } else { + return mPreloadInstanceMap.get(url); + } + } + + @Nullable + public WXSDKInstance fetchPreload(Context context, String url) { + WXSDKInstance instance = mPreloadInstanceMap.get(url); + return instance; + } + +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java b/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java index ac02fa8278..3c6aa5758a 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java @@ -28,10 +28,12 @@ import com.taobao.weex.common.WXRuntimeException; import com.taobao.weex.common.WXThread; import com.taobao.weex.dom.RenderContext; +import com.taobao.weex.prerender.PreRenderContext; import com.taobao.weex.performance.WXInstanceApm; import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.action.GraphicActionBatchAction; import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; import com.taobao.weex.utils.WXExceptionUtils; import com.taobao.weex.utils.WXUtils; @@ -48,6 +50,7 @@ public class WXRenderManager { private volatile ConcurrentHashMap mRenderContext; + private volatile ConcurrentHashMap mPreRenderContextMap; private WXRenderHandler mWXRenderHandler; private ArrayList> mBatchActions = new ArrayList<>(); private final int MAX_DROP_FRAME_NATIVE_BATCH = 2000; @@ -63,6 +66,10 @@ public RenderContext getRenderContext(String instanceId) { return mRenderContext.get(instanceId); } + public PreRenderContext getPreRenderContext(String instanceId) { + return mPreRenderContextMap.get(instanceId); + } + public @Nullable WXComponent getWXComponent(String instanceId, String ref) { if (instanceId == null || TextUtils.isEmpty(ref)) { @@ -72,6 +79,16 @@ WXComponent getWXComponent(String instanceId, String ref) { return stmt == null ? null : stmt.getComponent(ref); } + public @Nullable + WXComponentNode getWXComponentNode(String instanceId, String ref) { + if (instanceId == null || TextUtils.isEmpty(ref)) { + return null; + } + + PreRenderContext preRenderContext = getPreRenderContext(instanceId); + return preRenderContext == null ? null : preRenderContext.nodeMap.get(ref); + } + public WXSDKInstance getWXSDKInstance(String instanceId) { RenderContextImpl statement = mRenderContext.get(instanceId); if (statement == null) { @@ -171,6 +188,7 @@ public void registerInstance(WXSDKInstance instance) { null); } else { mRenderContext.put(instance.getInstanceId(), new RenderContextImpl(instance)); + mPreRenderContextMap.put(instance.getInstanceId(), instance.getPrerenderContext()); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java index f078d1b684..9dff389fa9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java @@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSONArray; import com.taobao.weex.WXSDKManager; import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; import com.taobao.weex.utils.WXLogUtils; /** @@ -44,11 +45,9 @@ public ActionInvokeMethod(String pageId, String ref, String method, JSONArray ar @Override public void executeAction() { - WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(mPageId, mRef); - if(component == null){ - WXLogUtils.e(TAG,"target component not found."); - return; + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(mPageId, mRef); + if (node != null) { + node.invokeMethod(mMethod, mArgs); } - component.invoke(mMethod,mArgs); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java index 9d124504b2..d6b78065b0 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java @@ -19,6 +19,7 @@ package com.taobao.weex.ui.action; import android.support.annotation.NonNull; +import android.text.TextUtils; import android.view.View; import com.taobao.weex.common.Constants; @@ -89,6 +90,34 @@ public final void addEvent(Set events) { mEvents.addAll(events); } + public final void addEvent(String event) { + if (TextUtils.isEmpty(event)) { + return; + } + + if (mEvents == null) { + mEvents = new WXEvent(); + } + + if (!mEvents.contains(event)) { + mEvents.add(event); + } + } + + public final void removeEvent(String event) { + if (TextUtils.isEmpty(event)) { + return; + } + + if (mEvents == null) { + mEvents = new WXEvent(); + } + + if (mEvents.contains(event)) { + mEvents.remove(event); + } + } + public final void addShorthand(float[] shorthand, CSSShorthand.TYPE type) { if (shorthand == null) { shorthand = new float[] {0, 0, 0, 0}; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java index 88baced440..c6668f2b3e 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java @@ -18,14 +18,13 @@ */ package com.taobao.weex.ui.action; -import android.support.v4.util.ArrayMap; +import android.support.annotation.NonNull; + import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.common.Constants; import com.taobao.weex.dom.CSSShorthand; -import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.WXComponentFactory; -import com.taobao.weex.ui.component.WXVContainer; +import com.taobao.weex.ui.component.node.WXComponentNodeBuilder; + import java.util.Map; import java.util.Set; @@ -47,17 +46,15 @@ public GraphicActionAbstractAddElement(WXSDKInstance instance, String ref) { startTime = System.currentTimeMillis(); } - protected WXComponent createComponent(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) { - long createComponentStart = System.currentTimeMillis(); - if (basicComponentData != null) { - basicComponentData.addStyle(mStyle); - basicComponentData.addAttr(mAttributes); - basicComponentData.addEvent(mEvents); - basicComponentData.addShorthand(mMargins, CSSShorthand.TYPE.MARGIN); - basicComponentData.addShorthand(mPaddings, CSSShorthand.TYPE.PADDING); - basicComponentData.addShorthand(mBorders, CSSShorthand.TYPE.BORDER); - } + protected WXComponentNodeBuilder createNode(WXSDKInstance instance, @NonNull BasicComponentData basicComponentData) { + basicComponentData.addStyle(mStyle); + basicComponentData.addAttr(mAttributes); + basicComponentData.addEvent(mEvents); + basicComponentData.addShorthand(mMargins, CSSShorthand.TYPE.MARGIN); + basicComponentData.addShorthand(mPaddings, CSSShorthand.TYPE.PADDING); + basicComponentData.addShorthand(mBorders, CSSShorthand.TYPE.BORDER); + return WXComponentNodeBuilder.createInstance(instance, basicComponentData); WXComponent component = WXComponentFactory.newInstance(instance, parent, basicComponentData); WXSDKManager.getInstance().getWXRenderManager().registerComponent(getPageId(), getRef(), component); if(mStyle != null && mStyle.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null) { diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java index 9db1ee16ab..5ec44dc76c 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java @@ -22,6 +22,7 @@ import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; import android.support.annotation.WorkerThread; + import android.support.v4.util.ArrayMap; import android.text.TextUtils; import android.util.Log; @@ -29,11 +30,13 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.common.WXErrorCode; +import com.taobao.weex.ui.component.node.WXComponentNode; import com.taobao.weex.dom.transition.WXTransition; import com.taobao.weex.performance.WXAnalyzerDataTransfer; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.utils.WXExceptionUtils; + import com.taobao.weex.utils.WXLogUtils; import java.util.Arrays; import java.util.Locale; @@ -42,11 +45,10 @@ public class GraphicActionAddElement extends GraphicActionAbstractAddElement { - private WXVContainer parent; - private WXComponent child; private GraphicPosition layoutPosition; private GraphicSize layoutSize; private boolean isLayoutRTL; + private WXComponentNode childNode; public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, String componentType, String parentRef, @@ -75,10 +77,15 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, Log.d(WXAnalyzerDataTransfer.INTERACTION_TAG, "[client][addelementStart]"+instance.getInstanceId()+","+componentType+","+ref); } try { - parent = (WXVContainer) WXSDKManager.getInstance().getWXRenderManager() - .getWXComponent(getPageId(), mParentRef); BasicComponentData basicComponentData = new BasicComponentData(ref, mComponentType, mParentRef); + childNode = createNode(instance, basicComponentData) + .setIndex(mIndex) + .setIsJSCreateFinish(instance.isJSCreateFinish) + .setLayoutPosition(layoutPosition) + .setLayoutSize(layoutSize).build(); + childNode.createComponent(); + child = createComponent(instance, parent, basicComponentData); child.setTransition(WXTransition.fromMap(child.getStyles(), child)); if (null != parent && parent.isIgnoreInteraction){ @@ -162,23 +169,26 @@ public void setRTL(boolean isRTL){ @WorkerThread public void setSize(GraphicSize graphicSize){ this.layoutSize = graphicSize; + childNode.setLayoutSize(graphicSize); } @RestrictTo(Scope.LIBRARY) @WorkerThread public void setPosition(GraphicPosition position){ this.layoutPosition = position; + childNode.setLayoutPosition(position); } @RestrictTo(Scope.LIBRARY) @WorkerThread public void setIndex(int index){ - mIndex = index; + childNode.setIndex(index); } @Override public void executeAction() { super.executeAction(); + childNode.addElement(); try { if (!TextUtils.equals(mComponentType, "video") && !TextUtils.equals(mComponentType, "videoplus")) child.mIsAddElementToTree = true; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java index 3ef4a6c79e..09caf95e33 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java @@ -23,6 +23,7 @@ import com.taobao.weex.dom.WXEvent; import com.taobao.weex.tracing.Stopwatch; import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; /** * Created by listen on 18/01/11. @@ -38,16 +39,17 @@ public GraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { @Override public void executeAction() { - WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null) { + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null || instance.getContext() == null) { return; } - Stopwatch.tick(); - if (!component.getEvents().contains(mEvent)) { - component.getEvents().addEvent(mEvent); + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.addEvent(mEvent); } component.addEvent(mEvent); Stopwatch.split("addEventToComponent"); + } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java index 4023b0c232..4ac3add3ed 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java @@ -115,7 +115,7 @@ public void executeAction() { } WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); - if (instance == null) { + if (instance == null || instance.getNeedInterceptRender()) { return; } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java index 49eef03112..ec8c2958b0 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java @@ -35,6 +35,7 @@ public class GraphicActionCreateBody extends GraphicActionAbstractAddElement { private WXComponent component; + private WXComponentNode node; public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, String componentType, @@ -58,6 +59,9 @@ public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, } BasicComponentData basicComponentData = new BasicComponentData(getRef(), mComponentType, null); + node = createNode(instance, basicComponentData).build(); + node.createComponent(); + // need merge component = createComponent(instance, null, basicComponentData); if (component == null) { return; @@ -68,6 +72,8 @@ public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, @Override public void executeAction() { super.executeAction(); + node.createBody(); + // needMerge try { component.createView(); component.applyLayoutAndEvent(component); diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java index 1addfd383a..d3ff49d9a7 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java @@ -18,12 +18,9 @@ */ package com.taobao.weex.ui.action; -import android.support.annotation.NonNull; - import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.common.WXRenderStrategy; -import com.taobao.weex.performance.WXInstanceApm; import com.taobao.weex.ui.component.WXComponent; /** @@ -35,6 +32,7 @@ public class GraphicActionCreateFinish extends BasicGraphicAction { private int mLayoutHeight; public GraphicActionCreateFinish(@NonNull WXSDKInstance instance) { + // need merge super(instance, ""); WXComponent component = instance.getRootComponent(); if (null != component) { @@ -43,10 +41,12 @@ public GraphicActionCreateFinish(@NonNull WXSDKInstance instance) { } instance.getApmForInstance().onStage(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH); instance.getApmForInstance().extInfo.put(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH,true); + } @Override public void executeAction() { + // need merge final WXSDKInstance instance = getWXSDKIntance(); if (instance == null || instance.getContext() == null) { return; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java index cffef17511..7472bdf428 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java @@ -21,6 +21,8 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.utils.WXLogUtils; public class GraphicActionLayout extends BasicGraphicAction { @@ -37,14 +39,19 @@ public GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition l @Override public void executeAction() { - WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null) { + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null || instance.getContext() == null) { + WXLogUtils.w(WXLogUtils.WEEX_TAG); return; } - +// need merge component.setIsLayoutRTL(mIsLayoutRTL); component.setDemission(mLayoutSize, mLayoutPosition); component.setSafeLayout(component); component.setPadding(component.getPadding(), component.getBorder()); + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.updateLayout(mLayoutPosition, mLayoutSize); + } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java index 424ee8416e..7affcc7c49 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java @@ -22,8 +22,7 @@ import android.text.TextUtils; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.WXVContainer; +import com.taobao.weex.ui.component.node.WXComponentNode; public class GraphicActionMoveElement extends BasicGraphicAction { @@ -38,6 +37,11 @@ public GraphicActionMoveElement(WXSDKInstance instance, String ref, String paren @Override public void executeAction() { + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.moveElement(mParentref, mIndex); + + // need merge WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); if(component == null) { return; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java index b7e45512ef..47c0454117 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java @@ -24,6 +24,7 @@ import com.taobao.weex.WXSDKManager; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXVContainer; +import com.taobao.weex.ui.component.node.WXComponentNode; public class GraphicActionRemoveElement extends BasicGraphicAction { @@ -33,6 +34,11 @@ public GraphicActionRemoveElement(WXSDKInstance instance, String ref) { @Override public void executeAction() { + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.removeElement(isJSCreateFinish); + + // need merge WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); if (component == null || component.getParent() == null || component.getInstance() == null) { return; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java index 67fe1335b1..e52d3e832a 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java @@ -21,8 +21,7 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.dom.WXEvent; -import com.taobao.weex.tracing.Stopwatch; -import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; /** * Created by listen on 18/01/11. @@ -38,13 +37,9 @@ public GraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event @Override public void executeAction() { - WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null) { - return; + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.removeEvent(mEvent); } - - Stopwatch.tick(); - component.removeEvent(mEvent); - Stopwatch.split("removeEventFromComponent"); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java index c03e93094a..c9f0a36d4d 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java @@ -21,8 +21,7 @@ import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.Scrollable; -import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; /** * Created by listen on 18/01/09. @@ -38,15 +37,9 @@ public GraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObje @Override public void executeAction() { - WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null) { - return; + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.scrollToElement(mOptions); } - - Scrollable scroller = component.getParentScroller(); - if (scroller == null) { - return; - } - scroller.scrollTo(component, mOptions); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java new file mode 100644 index 0000000000..d923719f24 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import android.support.annotation.NonNull; + +import com.taobao.weex.ui.component.node.WXComponentNode; + +/** + * Description + * Created by luciolong on 02/08/2018. + */ +public class GraphicActionTransformNode extends BasicGraphicAction { + @NonNull + private final WXComponentNode mNode; + + public GraphicActionTransformNode(@NonNull WXComponentNode node, String pageId, String ref) { + super(pageId, ref); + this.mNode = node; + } + + @Override + public void executeAction() { + mNode.transformNode(); + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java index 4e6a00f295..828d5f9662 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java @@ -20,35 +20,31 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; import java.util.Map; public class GraphicActionUpdateAttr extends BasicGraphicAction { private Map mAttrs; - private WXComponent component; + private WXComponentNode mNode; public GraphicActionUpdateAttr(WXSDKInstance instance, String ref, Map attrs) { super(instance, ref); this.mAttrs = attrs; - component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null) { - return; - } - if (mAttrs != null) { - component.addAttr(mAttrs); + mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (mNode != null) { + mNode.addAttrs(mAttrs); } } @Override public void executeAction() { - if (component == null) { + if (mNode == null) { return; } - component.getAttrs().mergeAttr(); - component.updateAttrs(mAttrs); + mNode.updateAttrs(mAttrs); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java index bddb338df2..dcda8707c7 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java @@ -27,13 +27,14 @@ import com.taobao.weex.dom.CSSShorthand; import com.taobao.weex.dom.transition.WXTransition; import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; import java.util.Map; public class GraphicActionUpdateStyle extends BasicGraphicAction { private Map mStyle; - private WXComponent component; + private WXComponentNode mNode; private boolean mIsCausedByPesudo; private boolean mIsBorderSet; @@ -54,32 +55,36 @@ public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, this.mStyle = style; this.mIsCausedByPesudo = byPesudo; - component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null) { + mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (mNode == null) { return; } if (null != mStyle) { - component.updateStyle(mStyle, mIsCausedByPesudo); - if(style.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null) { - Map animationMap = new ArrayMap<>(2); - animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); - animationMap - .put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); - component.addAnimationForElement(animationMap); + mNode.getComponentData().getStyles().updateStyle(mStyle, mIsCausedByPesudo); + if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { + if (style.containsKey(Constants.Name.TRANSFORM) && mNode.data.getTransition() == null) { + Map animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap + .put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + mNode.data.addAnimationForElement(animationMap); + } } } if (null != paddings) { - component.setPaddings(paddings); + mNode.getComponentData().setPaddings(paddings); } if (null != margins) { - component.setMargins(margins); + mNode.getComponentData().setMargins(margins); } if (null != borders) { mIsBorderSet = true; + // need merge component.setBorders(borders); + mNode.getComponentData().setBorders(borders); } } @@ -92,37 +97,41 @@ public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, this.mStyle = style; this.mIsCausedByPesudo = byPesudo; - component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null) { + mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (mNode == null) { return; } if (null != mStyle) { - component.addStyle(mStyle, mIsCausedByPesudo); - if(style.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null){ - Map animationMap = new ArrayMap<>(2); - animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); - animationMap.put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); - component.addAnimationForElement(animationMap); - WXBridgeManager.getInstance().markDirty(component.getInstanceId(), component.getRef(), true); + mNode.getComponentData().addStyle(mStyle, mIsCausedByPesudo); + if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { + if (style.containsKey(Constants.Name.TRANSFORM) && mNode.data.getTransition() == null) { + Map animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap.put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + mNode.data.addAnimationForElement(animationMap); + WXBridgeManager.getInstance().markDirty(getPageId(), getRef(), true); + } } } if (null != paddings) { - component.addShorthand(paddings); + mNode.getComponentData().addShorthand(paddings); } if (null != margins) { - component.addShorthand(margins); + mNode.getComponentData().addShorthand(margins); } if (null != borders) { mIsBorderSet = true; + // need merge component.addShorthand(borders); + mNode.getComponentData().addShorthand(borders); } } @Override - public void executeAction() { + public void executeAction() { // need merge if (component == null) return; if (mStyle != null) { if(component.getTransition() != null){ @@ -136,6 +145,24 @@ public void executeAction() { } } else if (mIsBorderSet) { component.updateStyles(component); + + + mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (mNode == null) { + return; + } + + if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { + WXComponent component = mNode.data; + if (component.getTransition() != null) { + component.getTransition().updateTranstionParams(mStyle); + if (component.getTransition().hasTransitionProperty(mStyle)) { + component.getTransition().startTransition(mStyle); + } + } else { + component.setTransition(WXTransition.fromMap(mStyle, component)); + component.updateStyles(mStyle); + } } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java new file mode 100644 index 0000000000..911f720568 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java @@ -0,0 +1,451 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package com.taobao.weex.ui.component.node; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.util.ArrayMap; +import android.text.TextUtils; +import android.widget.ScrollView; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.Constants; +import com.taobao.weex.common.WXRenderStrategy; +import com.taobao.weex.dom.WXStyle; +import com.taobao.weex.dom.transition.WXTransition; +import com.taobao.weex.tracing.Stopwatch; +import com.taobao.weex.ui.action.BasicComponentData; +import com.taobao.weex.ui.action.GraphicActionTransformNode; +import com.taobao.weex.ui.action.GraphicPosition; +import com.taobao.weex.ui.action.GraphicSize; +import com.taobao.weex.ui.component.Scrollable; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXComponentFactory; +import com.taobao.weex.ui.component.WXScroller; +import com.taobao.weex.ui.component.WXVContainer; +import com.taobao.weex.utils.WXLogUtils; + +import java.util.ArrayList; +import java.util.Map; + +/** + * Created by luciolong on 14/07/2018. + */ +public class WXComponentNode { + private static final String TAG = "WXComponentNode"; + + private static final int EXECUTE_STATE_CREATE_BODY = 1; + private static final int EXECUTE_STATE_ADD_ELEMENT = 2; + + @NonNull + private BasicComponentData mComponentData; + + // parent node + @Nullable + private WXComponentNode mParentNode; + + // child node + @NonNull + private final ArrayList mChildNodes = new ArrayList<>(); + + @NonNull + private WXSDKInstance mWxInstance; + + @Nullable + public WXComponent data; + + private int mIndex = 0; + + private GraphicPosition mLayoutPosition; + private GraphicSize mLayoutSize; + private JSONObject mScrollOptions; + + private boolean mIsJSCreateFinish = false; + + private int mExecuteState = EXECUTE_STATE_ADD_ELEMENT; + + WXComponentNode(@NonNull BasicComponentData data, + @NonNull Map map, + @NonNull WXSDKInstance instance) { + this.mComponentData = data; + this.mWxInstance = instance; + map.put(data.mRef, this); + if (!TextUtils.isEmpty(data.mParentRef)) { + this.mParentNode = map.get(data.mParentRef); + } + } + + public void setIndex(int index) { + this.mIndex = index; + } + + public void setLayoutPosition(GraphicPosition layoutPosition) { + this.mLayoutPosition = layoutPosition; + } + + public void setLayoutSize(GraphicSize layoutSize) { + this.mLayoutSize = layoutSize; + } + + void setIsJSCreateFinish(boolean isJSCreateFinish) { + this.mIsJSCreateFinish = isJSCreateFinish; + } + + public void startTransform() { + postTransformAction(); + if (mChildNodes.size() > 0) { + for (WXComponentNode node : mChildNodes) { + node.startTransform(); + } + } + } + + private void postTransformAction() { + new GraphicActionTransformNode(this, mWxInstance.getInstanceId(), mComponentData.mRef).executeActionOnRender(); + } + + public void transformNode() { + createComponent(); + + switch (mExecuteState) { + case EXECUTE_STATE_CREATE_BODY: + createBody(); + break; + case EXECUTE_STATE_ADD_ELEMENT: + addElement(); + break; + default: + break; + } + } + + public void createComponent() { + if (mWxInstance.getNeedInterceptRender()) { + mExecuteState = EXECUTE_STATE_CREATE_BODY; + return; + } + + if (data == null) { + long createComponentStart = System.currentTimeMillis(); + String pageId = mWxInstance.getInstanceId(); + WXVContainer parent = null; + if (mParentNode != null) { + parent = (WXVContainer) WXSDKManager.getInstance().getWXRenderManager() + .getWXComponent(pageId, mParentNode.mComponentData.mRef); + } + WXComponent component = WXComponentFactory.newInstance(mWxInstance, parent, mComponentData); + WXSDKManager.getInstance().getWXRenderManager().registerComponent(pageId, mComponentData.mRef, component); + WXStyle style = mComponentData.getStyles(); + if (style.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null) { + Map animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap + .put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + component.addAnimationForElement(animationMap); + } + mWxInstance.onComponentCreate(component, System.currentTimeMillis() - createComponentStart); + component.setTransition(WXTransition.fromMap(component.getStyles(), component)); + data = component; + } + } + + public void createBody() { + if (mWxInstance.getNeedInterceptRender()) { + mExecuteState = EXECUTE_STATE_ADD_ELEMENT; + return; + } + try { + ensureDataNotNull(); + if (data != null) { + data.createView(); + data.applyLayoutAndEvent(data); + data.bindData(data); + + if (data instanceof WXScroller) { + WXScroller scroller = (WXScroller) data; + if (scroller.getInnerView() instanceof ScrollView) { + mWxInstance.setRootScrollView((ScrollView) scroller.getInnerView()); + } + } + + mWxInstance.onRootCreated(data); + + if (mWxInstance.getRenderStrategy() != WXRenderStrategy.APPEND_ONCE) { + mWxInstance.onCreateFinish(); + } + } + } catch (Exception e) { + WXLogUtils.e("create body failed.", e); + } + } + + public void addElement() { + if (mParentNode == null) { + return; + } + mParentNode.addNode(this, mIndex); + if (mWxInstance.getNeedInterceptRender()) { + return; + } + + try { + ensureDataNotNull(); + if (data != null) { + mParentNode.addChild(this, mIndex); + mParentNode.createChildViewAt(mIndex); + + if (mLayoutPosition != null && mLayoutSize != null) { + data.setDemission(mLayoutSize, mLayoutPosition); + } + + data.applyLayoutAndEvent(data); + + data.bindData(data); + scrollToElementInternal(); + mWxInstance.onElementChange(mIsJSCreateFinish); + } + } catch (Exception e) { + WXLogUtils.e("add component failed.", e); + } + } + + private void addElementInternal(WXComponentNode childNode, int index) { + if (childNode.mParentNode != null) { + childNode.mParentNode.removeElementInternal(childNode, false); + } + childNode.mIndex = index; + addNode(childNode, index); + if (!mWxInstance.getNeedInterceptRender()) { + ensureDataNotNull(); + childNode.ensureDataNotNull(); + if (data instanceof WXVContainer && childNode.data != null) { + ((WXVContainer) data).addChild(childNode.data, index); + if (!data.isVirtualComponent()) { + ((WXVContainer) data).addSubView(childNode.data.getHostView(), mIndex); + } + } + } + } + + private void addNode(@NonNull WXComponentNode node, int index) { + int count = mChildNodes.size(); + index = index >= count ? -1 : index; + if (index == -1) { + mChildNodes.add(node); + } else { + mChildNodes.add(index, node); + } + } + + private void addChild(@NonNull WXComponentNode childNode, int index) { + ensureDataNotNull(); + childNode.ensureDataNotNull(); + + WXVContainer curContainer = (WXVContainer) WXSDKManager.getInstance().getWXRenderManager() + .getWXComponent(mWxInstance.getInstanceId(), mComponentData.mRef); + if (curContainer != null) { + curContainer.addChild(childNode.data, index); + } + } + + private void createChildViewAt(int index) { + ensureDataNotNull(); + + WXVContainer curContainer = (WXVContainer) WXSDKManager.getInstance().getWXRenderManager() + .getWXComponent(mWxInstance.getInstanceId(), mComponentData.mRef); + if (curContainer != null) { + curContainer.createChildViewAt(index); + } + } + + private void ensureDataNotNull() { + if (data == null) { + createComponent(); + } + } + + public void addEvent(String event) { + if (mWxInstance.getNeedInterceptRender()) { + mComponentData.addEvent(event); + return; + } + ensureDataNotNull(); + if (data != null) { + Stopwatch.tick(); + if (!data.getEvents().contains(event)) { + data.getEvents().addEvent(event); + } + data.addEvent(event); + Stopwatch.split("addEventToComponent"); + } + } + + public void invokeMethod(String method, JSONArray args) { + if (mWxInstance.getNeedInterceptRender()) { + return; + } + + ensureDataNotNull(); + if(data == null){ + WXLogUtils.e(WXLogUtils.WEEX_TAG, "invoke method, target component not found."); + return; + } + data.invoke(method, args); + } + + public void updateLayout(GraphicPosition layoutPosition, GraphicSize layoutSize) { + mLayoutSize = layoutSize; + mLayoutPosition = layoutPosition; + if (mWxInstance.getNeedInterceptRender()) { + return; + } + + ensureDataNotNull(); + if (data == null) { + WXLogUtils.e(WXLogUtils.WEEX_TAG, "update layout, target component not found."); + return; + } + + data.setDemission(mLayoutSize, mLayoutPosition); + data.setLayout(data); + data.setPadding(data.getPadding(), data.getBorder()); + } + + public void moveElement(String parentRef, int index) { + WXComponentNode oldParent = mParentNode; + WXComponentNode newParent = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(mWxInstance.getInstanceId(), parentRef); + + if (oldParent == null || newParent == null) { + WXLogUtils.e(WXLogUtils.WEEX_TAG, "move element, find parent error"); + return; + } + + oldParent.removeElementInternal(this, false); + newParent.addElementInternal(this, index); + } + + public void removeElement(boolean isJSCreateFinish) { + mIsJSCreateFinish = isJSCreateFinish; + if (!mWxInstance.getNeedInterceptRender() && data != null) { + clearRegistryForComponent(data); + } + if (mParentNode != null && data != null) { + mParentNode.removeElementInternal(this, true); + } + } + + private void removeElementInternal(@NonNull WXComponentNode node, boolean destroy) { + if (this.mChildNodes.contains(node)) { + this.mChildNodes.remove(node); + } + node.mParentNode = null; + + if (!mWxInstance.getNeedInterceptRender() && data instanceof WXVContainer && node.data != null) { + ((WXVContainer)data).remove(node.data, destroy); + } + } + + private void clearRegistryForComponent(WXComponent component) { + WXComponent removedComponent = WXSDKManager.getInstance().getWXRenderManager().unregisterComponent(mWxInstance.getInstanceId(), mComponentData.mRef); + if (removedComponent != null) { + removedComponent.removeAllEvent(); + removedComponent.removeStickyStyle(); + } + if (component instanceof WXVContainer) { + WXVContainer container = (WXVContainer) component; + int count = container.childCount(); + for (int i = count - 1; i >= 0; --i) { + clearRegistryForComponent(container.getChild(i)); + } + } + mWxInstance.onElementChange(mIsJSCreateFinish); + } + + public void removeEvent(String event) { + if (mWxInstance.getNeedInterceptRender()) { + mComponentData.removeEvent(event); + return; + } + ensureDataNotNull(); + if (data != null) { + Stopwatch.tick(); + data.removeEvent(event); + Stopwatch.split("removeEventFromComponent"); + } + } + + public void scrollToElement(JSONObject scrollOptions) { + if (mWxInstance.getNeedInterceptRender()) { + mScrollOptions = scrollOptions; + } else { + scrollToElementInternal(); + } + } + + private void scrollToElementInternal() { + ensureDataNotNull(); + if (data != null && mScrollOptions != null) { + Scrollable scroller = data.getParentScroller(); + if (scroller == null) { + return; + } + scroller.scrollTo(data, mScrollOptions); + mScrollOptions = null; + } + } + + public void addAttrs(Map attrs) { + if (attrs != null) { + mComponentData.addAttr(attrs); + + if (!mWxInstance.getNeedInterceptRender()) { + ensureDataNotNull(); + if (data != null) { + data.addAttr(attrs); + } + } + } + } + + public void updateAttrs(Map attrs) { + if (attrs != null) { + mComponentData.getAttrs().mergeAttr(); + if (!mWxInstance.getNeedInterceptRender()) { + ensureDataNotNull(); + if (data != null) { + data.updateAttrs(attrs); + } + } + } + } + + @NonNull + public BasicComponentData getComponentData() { + return mComponentData; + } + + @NonNull + public WXSDKInstance getWxInstance() { + return mWxInstance; + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNodeBuilder.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNodeBuilder.java new file mode 100644 index 0000000000..598f14164c --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNodeBuilder.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +package com.taobao.weex.ui.component.node; + +import android.support.annotation.NonNull; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.action.BasicComponentData; +import com.taobao.weex.ui.action.GraphicPosition; +import com.taobao.weex.ui.action.GraphicSize; + +/** + * Created by luciolong on 30/07/2018. + */ +public class WXComponentNodeBuilder { + @NonNull + private final WXSDKInstance mInstance; + + @NonNull + private final BasicComponentData mData; + + private int mIndex = 0; + + private GraphicPosition mLayoutPosition; + private GraphicSize mLayoutSize; + + private boolean mIsJSCreateFinish = false; + + private WXComponentNodeBuilder(@NonNull WXSDKInstance instance, @NonNull BasicComponentData data) { + mInstance = instance; + mData = data; + } + + public static WXComponentNodeBuilder createInstance(@NonNull WXSDKInstance instance, + @NonNull BasicComponentData data) { + return new WXComponentNodeBuilder(instance, data); + } + + public WXComponentNode build() { + WXComponentNode node = new WXComponentNode(mData, mInstance.getNodeMap(), mInstance); + node.setIndex(mIndex); + node.setLayoutPosition(mLayoutPosition); + node.setLayoutSize(mLayoutSize); + node.setIsJSCreateFinish(mIsJSCreateFinish); + return node; + } + + public WXComponentNodeBuilder setIndex(int index) { + this.mIndex = index; + return this; + } + + public WXComponentNodeBuilder setLayoutPosition(GraphicPosition layoutPosition) { + this.mLayoutPosition = layoutPosition; + return this; + } + + public WXComponentNodeBuilder setLayoutSize(GraphicSize layoutSize) { + this.mLayoutSize = layoutSize; + return this; + } + + public WXComponentNodeBuilder setIsJSCreateFinish(boolean isJSCreateFinish) { + this.mIsJSCreateFinish = isJSCreateFinish; + return this; + } +} From ff7b702326659bb8e76494d733aa77766c2f6f93 Mon Sep 17 00:00:00 2001 From: luciolong Date: Fri, 28 Dec 2018 16:28:00 +0800 Subject: [PATCH 02/13] [Android]prerender merge conflict fix --- .../java/com/taobao/weex/WXSDKInstance.java | 6 ++ .../GraphicActionAbstractAddElement.java | 12 --- .../ui/action/GraphicActionAddElement.java | 41 +--------- .../weex/ui/action/GraphicActionAddEvent.java | 5 -- .../ui/action/GraphicActionCreateBody.java | 34 +-------- .../ui/action/GraphicActionCreateFinish.java | 28 ++----- .../weex/ui/action/GraphicActionLayout.java | 8 +- .../ui/action/GraphicActionMoveElement.java | 29 -------- .../ui/action/GraphicActionRemoveElement.java | 36 +-------- .../ui/action/GraphicActionRenderSuccess.java | 13 ++-- .../ui/action/GraphicActionTransformNode.java | 5 +- .../ui/action/GraphicActionUpdateStyle.java | 37 +++------- .../ui/action/UpdateComponentDataAction.java | 1 + .../ui/component/node/WXComponentNode.java | 74 +++++++++++++++---- .../node/WXComponentNodeBuilder.java | 8 -- 15 files changed, 99 insertions(+), 238 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java index 25e86dbca9..76d62a0d8c 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java @@ -141,6 +141,12 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan private WXInstanceApm mApmForInstance; private @NonNull FlatGUIContext mFlatGUIContext =new FlatGUIContext(); + @NonNull + private PreRenderContext mPrerenderContext = new PreRenderContext(); + + private Map mContainerInfo; + + public boolean isNewFsEnd = false; /** * bundle type diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java index c6668f2b3e..44c0f91c02 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java @@ -21,7 +21,6 @@ import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.WXSDKManager; import com.taobao.weex.dom.CSSShorthand; import com.taobao.weex.ui.component.node.WXComponentNodeBuilder; @@ -55,17 +54,6 @@ protected WXComponentNodeBuilder createNode(WXSDKInstance instance, @NonNull Bas basicComponentData.addShorthand(mBorders, CSSShorthand.TYPE.BORDER); return WXComponentNodeBuilder.createInstance(instance, basicComponentData); - WXComponent component = WXComponentFactory.newInstance(instance, parent, basicComponentData); - WXSDKManager.getInstance().getWXRenderManager().registerComponent(getPageId(), getRef(), component); - if(mStyle != null && mStyle.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null) { - Map animationMap = new ArrayMap<>(2); - animationMap.put(Constants.Name.TRANSFORM, mStyle.get(Constants.Name.TRANSFORM)); - animationMap - .put(Constants.Name.TRANSFORM_ORIGIN, mStyle.get(Constants.Name.TRANSFORM_ORIGIN)); - component.addAnimationForElement(animationMap); - } - instance.onComponentCreate(component,System.currentTimeMillis() -createComponentStart); - return component; } @Override diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java index 5ec44dc76c..095036af16 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java @@ -24,20 +24,15 @@ import android.support.annotation.WorkerThread; import android.support.v4.util.ArrayMap; -import android.text.TextUtils; import android.util.Log; -import com.taobao.weex.BuildConfig; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.common.WXErrorCode; import com.taobao.weex.ui.component.node.WXComponentNode; -import com.taobao.weex.dom.transition.WXTransition; import com.taobao.weex.performance.WXAnalyzerDataTransfer; import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.utils.WXExceptionUtils; -import com.taobao.weex.utils.WXLogUtils; import java.util.Arrays; import java.util.Locale; import java.util.Map; @@ -81,26 +76,10 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, mParentRef); childNode = createNode(instance, basicComponentData) .setIndex(mIndex) - .setIsJSCreateFinish(instance.isJSCreateFinish) .setLayoutPosition(layoutPosition) .setLayoutSize(layoutSize).build(); childNode.createComponent(); - child = createComponent(instance, parent, basicComponentData); - child.setTransition(WXTransition.fromMap(child.getStyles(), child)); - if (null != parent && parent.isIgnoreInteraction){ - child.isIgnoreInteraction = true; - } - if (!child.isIgnoreInteraction ){ - Object flag = null; - if (null != child.getAttrs()){ - flag = child.getAttrs().get("ignoreInteraction"); - } - if ("1".equals(flag) || "true".equals(flag) || child.isFixed()){ - child.isIgnoreInteraction = true; - } - } - } catch (ClassCastException e) { Map ext = new ArrayMap<>(); WXComponent parent = WXSDKManager.getInstance().getWXRenderManager() @@ -162,7 +141,8 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, @RestrictTo(Scope.LIBRARY) @WorkerThread public void setRTL(boolean isRTL){ - this.isLayoutRTL = isRTL; + isLayoutRTL = isRTL; + childNode.setIsLayoutRTL(isRTL); } @RestrictTo(Scope.LIBRARY) @@ -188,22 +168,7 @@ public void setIndex(int index){ @Override public void executeAction() { super.executeAction(); + childNode.setIsLayoutRTL(isLayoutRTL); childNode.addElement(); - try { - if (!TextUtils.equals(mComponentType, "video") && !TextUtils.equals(mComponentType, "videoplus")) - child.mIsAddElementToTree = true; - - parent.addChild(child, mIndex); - parent.createChildViewAt(mIndex); - - child.setIsLayoutRTL(isLayoutRTL); - if(layoutPosition !=null && layoutSize != null) { - child.setDemission(layoutSize, layoutPosition); - } - child.applyLayoutAndEvent(child); - child.bindData(child); - } catch (Exception e) { - WXLogUtils.e("add component failed.", e); - } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java index 09caf95e33..2a50b0f054 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java @@ -21,8 +21,6 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.dom.WXEvent; -import com.taobao.weex.tracing.Stopwatch; -import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.node.WXComponentNode; /** @@ -48,8 +46,5 @@ public void executeAction() { if (node != null) { node.addEvent(mEvent); } - component.addEvent(mEvent); - Stopwatch.split("addEventToComponent"); - } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java index ec8c2958b0..fe1fa86f0a 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java @@ -19,15 +19,10 @@ package com.taobao.weex.ui.action; import android.support.annotation.NonNull; -import android.widget.ScrollView; import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.WXSDKManager; -import com.taobao.weex.common.WXRenderStrategy; -import com.taobao.weex.dom.transition.WXTransition; import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.WXScroller; -import com.taobao.weex.utils.WXLogUtils; +import com.taobao.weex.ui.component.node.WXComponentNode; import java.util.Map; import java.util.Set; @@ -61,39 +56,12 @@ public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, BasicComponentData basicComponentData = new BasicComponentData(getRef(), mComponentType, null); node = createNode(instance, basicComponentData).build(); node.createComponent(); - // need merge - component = createComponent(instance, null, basicComponentData); - if (component == null) { - return; - } - component.setTransition(WXTransition.fromMap(component.getStyles(), component)); } @Override public void executeAction() { super.executeAction(); node.createBody(); - // needMerge - try { - component.createView(); - component.applyLayoutAndEvent(component); - component.bindData(component); - WXSDKInstance instance = getWXSDKIntance(); - - if (component instanceof WXScroller) { - WXScroller scroller = (WXScroller) component; - if (scroller.getInnerView() instanceof ScrollView) { - instance.setRootScrollView((ScrollView) scroller.getInnerView()); - } - } - instance.onRootCreated(component); - - if (instance.getRenderStrategy() != WXRenderStrategy.APPEND_ONCE) { - instance.onCreateFinish(); - } - } catch (Exception e) { - WXLogUtils.e("create body failed.", e); - } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java index d3ff49d9a7..039643c0fe 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java @@ -18,27 +18,18 @@ */ package com.taobao.weex.ui.action; +import android.support.annotation.NonNull; + import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.WXSDKManager; -import com.taobao.weex.common.WXRenderStrategy; -import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.performance.WXInstanceApm; /** * Created by listen on 18/01/09. */ public class GraphicActionCreateFinish extends BasicGraphicAction { - private int mLayoutWidth; - private int mLayoutHeight; - public GraphicActionCreateFinish(@NonNull WXSDKInstance instance) { - // need merge super(instance, ""); - WXComponent component = instance.getRootComponent(); - if (null != component) { - this.mLayoutWidth = (int) component.getLayoutWidth(); - this.mLayoutHeight = (int) component.getLayoutHeight(); - } instance.getApmForInstance().onStage(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH); instance.getApmForInstance().extInfo.put(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH,true); @@ -46,21 +37,14 @@ public GraphicActionCreateFinish(@NonNull WXSDKInstance instance) { @Override public void executeAction() { - // need merge final WXSDKInstance instance = getWXSDKIntance(); - if (instance == null || instance.getContext() == null) { + if (instance == null) { return; } - instance.mHasCreateFinish = true; - - if (instance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) { - instance.onCreateFinish(); + if (instance.getPrerenderContext().rootNode != null) { + instance.getPrerenderContext().rootNode.onCreateFinish(); } - if (null != instance.getWXPerformance()){ - instance.getWXPerformance().callCreateFinishTime = System.currentTimeMillis()-instance.getWXPerformance().renderTimeOrigin; - } - instance.onOldFsRenderTimeLogic(); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java index 7472bdf428..71ab74b523 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java @@ -44,14 +44,10 @@ public void executeAction() { WXLogUtils.w(WXLogUtils.WEEX_TAG); return; } -// need merge - component.setIsLayoutRTL(mIsLayoutRTL); - component.setDemission(mLayoutSize, mLayoutPosition); - component.setSafeLayout(component); - component.setPadding(component.getPadding(), component.getBorder()); + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); if (node != null) { - node.updateLayout(mLayoutPosition, mLayoutSize); + node.updateLayout(mLayoutPosition, mLayoutSize, mIsLayoutRTL); } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java index 7affcc7c49..16935ad7b9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java @@ -40,35 +40,6 @@ public void executeAction() { WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); if (node != null) { node.moveElement(mParentref, mIndex); - - // need merge - WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if(component == null) { - return; - } - WXVContainer oldParent = component.getParent(); - WXComponent newParent = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentref); - if (oldParent == null - || newParent == null || !(newParent instanceof WXVContainer)) { - return; - } - - if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) { - int[] location = new int[2] ; - component.getHostView().getLocationInWindow(location); - } - - oldParent.remove(component, false); - - ((WXVContainer) newParent).addChild(component, mIndex); - - if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) { - int[] location = new int[2] ; - component.getHostView().getLocationInWindow(location); - } - - if (!component.isVirtualComponent()) { - ((WXVContainer) newParent).addSubView(component.getHostView(), mIndex); } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java index 47c0454117..01191d96d9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java @@ -18,12 +18,8 @@ */ package com.taobao.weex.ui.action; -import android.text.TextUtils; - import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.ui.component.node.WXComponentNode; public class GraphicActionRemoveElement extends BasicGraphicAction { @@ -36,37 +32,7 @@ public GraphicActionRemoveElement(WXSDKInstance instance, String ref) { public void executeAction() { WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); if (node != null) { - node.removeElement(isJSCreateFinish); - - // need merge - WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null || component.getParent() == null || component.getInstance() == null) { - return; - } - clearRegistryForComponent(component); - WXVContainer parent = component.getParent(); - - if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) { - int[] location = new int[2]; - component.getHostView().getLocationInWindow(location); - //component.getInstance().onChangeElement(parent, location[1] > component.getInstance().getWeexHeight() + 1); - } - - parent.remove(component, true); - } - - private void clearRegistryForComponent(WXComponent component) { - WXComponent removedComponent = WXSDKManager.getInstance().getWXRenderManager().unregisterComponent(getPageId(), getRef()); - if (removedComponent != null) { - removedComponent.removeAllEvent(); - removedComponent.removeStickyStyle(); - } - if (component instanceof WXVContainer) { - WXVContainer container = (WXVContainer) component; - int count = container.childCount(); - for (int i = count - 1; i >= 0; --i) { - clearRegistryForComponent(container.getChild(i)); - } + node.removeElement(); } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java index ecd12b1102..e6b7ebf165 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java @@ -22,6 +22,7 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; public class GraphicActionRenderSuccess extends BasicGraphicAction { @@ -32,17 +33,13 @@ public GraphicActionRenderSuccess(@NonNull WXSDKInstance instance) { @Override public void executeAction() { final WXSDKInstance instance = getWXSDKIntance(); - if (instance == null || instance.getContext() == null) { + if (instance == null) { return; } - WXComponent component = instance.getRootComponent(); - int layoutWidth = 0; - int layoutHeight = 0; - if (null != component) { - layoutWidth = (int) component.getLayoutWidth(); - layoutHeight = (int) component.getLayoutHeight(); + WXComponentNode rootNode = instance.getPrerenderContext().rootNode; + if (rootNode != null) { + rootNode.onRenderSuccess(); } - instance.onRenderSuccess(layoutWidth, layoutHeight); } } \ No newline at end of file diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java index d923719f24..82c4671c6f 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java @@ -20,6 +20,7 @@ import android.support.annotation.NonNull; +import com.taobao.weex.WXSDKInstance; import com.taobao.weex.ui.component.node.WXComponentNode; /** @@ -30,8 +31,8 @@ public class GraphicActionTransformNode extends BasicGraphicAction { @NonNull private final WXComponentNode mNode; - public GraphicActionTransformNode(@NonNull WXComponentNode node, String pageId, String ref) { - super(pageId, ref); + public GraphicActionTransformNode(@NonNull WXComponentNode node, WXSDKInstance instance, String ref) { + super(instance, ref); this.mNode = node; } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java index dcda8707c7..0bd05e3d28 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java @@ -82,8 +82,6 @@ public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, if (null != borders) { mIsBorderSet = true; - // need merge - component.setBorders(borders); mNode.getComponentData().setBorders(borders); } } @@ -124,29 +122,12 @@ public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, if (null != borders) { mIsBorderSet = true; - // need merge - component.addShorthand(borders); mNode.getComponentData().addShorthand(borders); } } @Override public void executeAction() { // need merge - if (component == null) return; - if (mStyle != null) { - if(component.getTransition() != null){ - component.getTransition().updateTranstionParams(mStyle); - if(component.getTransition().hasTransitionProperty(mStyle)){ - component.getTransition().startTransition(mStyle); - } - } else { - component.setTransition(WXTransition.fromMap(mStyle, component)); - component.updateStyles(mStyle); - } - } else if (mIsBorderSet) { - component.updateStyles(component); - - mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); if (mNode == null) { return; @@ -154,14 +135,18 @@ public void executeAction() { // need merge if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { WXComponent component = mNode.data; - if (component.getTransition() != null) { - component.getTransition().updateTranstionParams(mStyle); - if (component.getTransition().hasTransitionProperty(mStyle)) { - component.getTransition().startTransition(mStyle); + if (mStyle != null) { + if (component.getTransition() != null) { + component.getTransition().updateTranstionParams(mStyle); + if (component.getTransition().hasTransitionProperty(mStyle)) { + component.getTransition().startTransition(mStyle); + } + } else { + component.setTransition(WXTransition.fromMap(mStyle, component)); + component.updateStyles(mStyle); } - } else { - component.setTransition(WXTransition.fromMap(mStyle, component)); - component.updateStyles(mStyle); + } else if (mIsBorderSet) { + component.updateStyles(component); } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java index b5e412e036..2b07955ae1 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java @@ -51,6 +51,7 @@ public UpdateComponentDataAction(WXSDKInstance instance, String virtualComponent @Override public void executeAction() { + // todo recyclerList这里暂时还不支持预渲染,后续再补上 if(TextUtils.isEmpty(getRef())){ WXLogUtils.e("wrong virtualComponentId split error " + virtualComponentId); return; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java index 911f720568..f7ce602e84 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java @@ -78,10 +78,9 @@ public class WXComponentNode { private GraphicPosition mLayoutPosition; private GraphicSize mLayoutSize; + private boolean mIsLayoutRTL; private JSONObject mScrollOptions; - private boolean mIsJSCreateFinish = false; - private int mExecuteState = EXECUTE_STATE_ADD_ELEMENT; WXComponentNode(@NonNull BasicComponentData data, @@ -107,8 +106,8 @@ public void setLayoutSize(GraphicSize layoutSize) { this.mLayoutSize = layoutSize; } - void setIsJSCreateFinish(boolean isJSCreateFinish) { - this.mIsJSCreateFinish = isJSCreateFinish; + public void setIsLayoutRTL(boolean isRTL) { + this.mIsLayoutRTL = isRTL; } public void startTransform() { @@ -121,7 +120,7 @@ public void startTransform() { } private void postTransformAction() { - new GraphicActionTransformNode(this, mWxInstance.getInstanceId(), mComponentData.mRef).executeActionOnRender(); + new GraphicActionTransformNode(this, mWxInstance, mComponentData.mRef).executeActionOnRender(); } public void transformNode() { @@ -153,6 +152,7 @@ public void createComponent() { parent = (WXVContainer) WXSDKManager.getInstance().getWXRenderManager() .getWXComponent(pageId, mParentNode.mComponentData.mRef); } + WXComponent component = WXComponentFactory.newInstance(mWxInstance, parent, mComponentData); WXSDKManager.getInstance().getWXRenderManager().registerComponent(pageId, mComponentData.mRef, component); WXStyle style = mComponentData.getStyles(); @@ -165,6 +165,16 @@ public void createComponent() { } mWxInstance.onComponentCreate(component, System.currentTimeMillis() - createComponentStart); component.setTransition(WXTransition.fromMap(component.getStyles(), component)); + + if (null != parent && parent.isIgnoreInteraction){ + component.isIgnoreInteraction = true; + } + if (!component.isIgnoreInteraction ){ + Object flag = component.getAttrs().get("ignoreInteraction"); + if ("1".equals(flag) || "true".equals(flag) || component.isFixed()){ + component.isIgnoreInteraction = true; + } + } data = component; } } @@ -194,6 +204,7 @@ public void createBody() { mWxInstance.onCreateFinish(); } } + } catch (Exception e) { WXLogUtils.e("create body failed.", e); } @@ -211,9 +222,12 @@ public void addElement() { try { ensureDataNotNull(); if (data != null) { + if (!TextUtils.equals(mComponentData.mComponentType, "video") && !TextUtils.equals(mComponentData.mComponentType, "videoplus")) + data.mIsAddElementToTree = true; mParentNode.addChild(this, mIndex); mParentNode.createChildViewAt(mIndex); + data.setIsLayoutRTL(mIsLayoutRTL); if (mLayoutPosition != null && mLayoutSize != null) { data.setDemission(mLayoutSize, mLayoutPosition); } @@ -222,8 +236,8 @@ public void addElement() { data.bindData(data); scrollToElementInternal(); - mWxInstance.onElementChange(mIsJSCreateFinish); } + } catch (Exception e) { WXLogUtils.e("add component failed.", e); } @@ -313,9 +327,10 @@ public void invokeMethod(String method, JSONArray args) { data.invoke(method, args); } - public void updateLayout(GraphicPosition layoutPosition, GraphicSize layoutSize) { + public void updateLayout(GraphicPosition layoutPosition, GraphicSize layoutSize, boolean isLayoutRTL) { mLayoutSize = layoutSize; mLayoutPosition = layoutPosition; + mIsLayoutRTL = isLayoutRTL; if (mWxInstance.getNeedInterceptRender()) { return; } @@ -326,8 +341,9 @@ public void updateLayout(GraphicPosition layoutPosition, GraphicSize layoutSize) return; } + data.setIsLayoutRTL(mIsLayoutRTL); data.setDemission(mLayoutSize, mLayoutPosition); - data.setLayout(data); + data.setSafeLayout(data); data.setPadding(data.getPadding(), data.getBorder()); } @@ -344,8 +360,7 @@ public void moveElement(String parentRef, int index) { newParent.addElementInternal(this, index); } - public void removeElement(boolean isJSCreateFinish) { - mIsJSCreateFinish = isJSCreateFinish; + public void removeElement() { if (!mWxInstance.getNeedInterceptRender() && data != null) { clearRegistryForComponent(data); } @@ -378,7 +393,6 @@ private void clearRegistryForComponent(WXComponent component) { clearRegistryForComponent(container.getChild(i)); } } - mWxInstance.onElementChange(mIsJSCreateFinish); } public void removeEvent(String event) { @@ -395,9 +409,8 @@ public void removeEvent(String event) { } public void scrollToElement(JSONObject scrollOptions) { - if (mWxInstance.getNeedInterceptRender()) { - mScrollOptions = scrollOptions; - } else { + mScrollOptions = scrollOptions; + if (!mWxInstance.getNeedInterceptRender()) { scrollToElementInternal(); } } @@ -448,4 +461,37 @@ public BasicComponentData getComponentData() { public WXSDKInstance getWxInstance() { return mWxInstance; } + + public void onCreateFinish() { + if (mWxInstance.getNeedInterceptRender()) { + return; + } + + mWxInstance.mHasCreateFinish = true; + + if (mWxInstance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) { + mWxInstance.onCreateFinish(); + } + + if (null != mWxInstance.getWXPerformance()){ + mWxInstance.getWXPerformance().callCreateFinishTime = System.currentTimeMillis() - mWxInstance.getWXPerformance().renderTimeOrigin; + } + mWxInstance.onOldFsRenderTimeLogic(); + } + + public void onRenderSuccess() { + if (mWxInstance.getNeedInterceptRender()) { + return; + } + + ensureDataNotNull(); + + int layoutWidth = 0; + int layoutHeight = 0; + if (null != data) { + layoutWidth = (int) data.getLayoutWidth(); + layoutHeight = (int) data.getLayoutHeight(); + } + mWxInstance.onRenderSuccess(layoutWidth, layoutHeight); + } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNodeBuilder.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNodeBuilder.java index 598f14164c..1877b74678 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNodeBuilder.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNodeBuilder.java @@ -42,8 +42,6 @@ public class WXComponentNodeBuilder { private GraphicPosition mLayoutPosition; private GraphicSize mLayoutSize; - private boolean mIsJSCreateFinish = false; - private WXComponentNodeBuilder(@NonNull WXSDKInstance instance, @NonNull BasicComponentData data) { mInstance = instance; mData = data; @@ -59,7 +57,6 @@ public WXComponentNode build() { node.setIndex(mIndex); node.setLayoutPosition(mLayoutPosition); node.setLayoutSize(mLayoutSize); - node.setIsJSCreateFinish(mIsJSCreateFinish); return node; } @@ -77,9 +74,4 @@ public WXComponentNodeBuilder setLayoutSize(GraphicSize layoutSize) { this.mLayoutSize = layoutSize; return this; } - - public WXComponentNodeBuilder setIsJSCreateFinish(boolean isJSCreateFinish) { - this.mIsJSCreateFinish = isJSCreateFinish; - return this; - } } From 20b93b4ffb6480ae9d0648e0714329a9b6ac889d Mon Sep 17 00:00:00 2001 From: luciolong Date: Tue, 14 Aug 2018 14:37:37 +0800 Subject: [PATCH 03/13] [Android] weex prerender fix --- .../java/com/taobao/weex/WXSDKInstance.java | 14 ++- .../weex/prerender/WXPrerenderManager.java | 26 +++-- .../com/taobao/weex/ui/WXRenderManager.java | 1 + .../ui/action/GraphicActionAddElement.java | 99 ++++++++++--------- .../ui/action/GraphicActionCreateBody.java | 3 - .../ui/action/GraphicActionMoveElement.java | 1 - .../ui/action/GraphicActionTransformNode.java | 1 + .../ui/component/node/WXComponentNode.java | 20 ++-- 8 files changed, 99 insertions(+), 66 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java index 76d62a0d8c..9cd25bbdd1 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java @@ -269,7 +269,7 @@ public void setUseSingleProcess(boolean flag) { WXBridgeManager.getInstance().setUseSingleProcess(flag); } - public void preRender(String pageName, final String url, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + public void preRenderByUrl(String pageName, final String url, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { if (mPrerenderContext.interceptRenderState.compareAndSet(PreRenderContext.INTERCEPT_RENDER_CLOSE, PreRenderContext.INTERCEPT_RENDER_OPEN)) { mPrerenderContext.width = width; mPrerenderContext.height = height; @@ -277,6 +277,14 @@ public void preRender(String pageName, final String url, Map opt } } + public void preRenderByTemplate(String pageName, final String template, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + if (mPrerenderContext.interceptRenderState.compareAndSet(PreRenderContext.INTERCEPT_RENDER_CLOSE, PreRenderContext.INTERCEPT_RENDER_OPEN)) { + mPrerenderContext.width = width; + mPrerenderContext.height = height; + render(pageName, template, options, jsonInitData, flag); + } + } + public void realRender(@NonNull Context context) { if (mPrerenderContext.interceptRenderState.compareAndSet(PreRenderContext.INTERCEPT_RENDER_OPEN, PreRenderContext.INTERCEPT_RENDER_CLOSE)) { mContext = context; @@ -287,6 +295,10 @@ public void realRender(@NonNull Context context) { } } + public void specifiedRootNode(WXComponentNode rootNode) { + mPrerenderContext.rootNode = rootNode; + } + @NonNull public PreRenderContext getPrerenderContext() { return mPrerenderContext; diff --git a/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java b/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java index 5302e9d125..b04062e351 100644 --- a/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java @@ -44,10 +44,25 @@ public static WXPrerenderManager getInstance() { private WXPrerenderManager() { } - public WXSDKInstance preload(String pageName, final String url, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + public WXSDKInstance preRenderByUrl(Context context, String pageName, final String url, + Map options, final String jsonInitData, + final int width, final int height, final WXRenderStrategy flag) { if (!mPreloadInstanceMap.containsKey(url)) { - WXSDKInstance instance = new WXSDKInstance(null); - instance.preRender(pageName, url, options, jsonInitData, width, height, flag); + WXSDKInstance instance = new WXSDKInstance(context); + instance.preRenderByUrl(pageName, url, options, jsonInitData, width, height, flag); + mPreloadInstanceMap.put(url, instance); + return instance; + } else { + return mPreloadInstanceMap.get(url); + } + } + + public WXSDKInstance preRenderByTemplate(Context context, String pageName, final String url, + String template, Map options, final String jsonInitData, + final int width, final int height, final WXRenderStrategy flag) { + if (!mPreloadInstanceMap.containsKey(url)) { + WXSDKInstance instance = new WXSDKInstance(context); + instance.preRenderByTemplate(pageName, template, options, jsonInitData, width, height, flag); mPreloadInstanceMap.put(url, instance); return instance; } else { @@ -56,9 +71,8 @@ public WXSDKInstance preload(String pageName, final String url, Map(); + mPreRenderContextMap = new ConcurrentHashMap<>(); mWXRenderHandler = new WXRenderHandler(); } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java index 095036af16..417764da1e 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java @@ -18,7 +18,6 @@ */ package com.taobao.weex.ui.action; -import android.support.annotation.NonNull; import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; import android.support.annotation.WorkerThread; @@ -85,55 +84,57 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, WXComponent parent = WXSDKManager.getInstance().getWXRenderManager() .getWXComponent(getPageId(), mParentRef); - if (mStyle != null && !mStyle.isEmpty()) { - ext.put("child.style", mStyle.toString()); + if (parent != null) { + if (mStyle != null && !mStyle.isEmpty()) { + ext.put("child.style", mStyle.toString()); + } + if (parent != null && parent.getStyles() != null && !parent.getStyles().isEmpty()) { + ext.put("parent.style", parent.getStyles().toString()); + } + + if (mAttributes != null && !mAttributes.isEmpty()) { + ext.put("child.attr", mAttributes.toString()); + } + if (parent != null && parent.getAttrs() != null && !parent.getAttrs().isEmpty()) { + ext.put("parent.attr", parent.getAttrs().toString()); + } + + if (mEvents != null && !mEvents.isEmpty()) { + ext.put("child.event", mEvents.toString()); + } + if (parent != null && parent.getEvents() != null && !parent.getEvents().isEmpty()) { + ext.put("parent.event", parent.getEvents().toString()); + } + + if (mMargins != null && mMargins.length > 0) { + ext.put("child.margin", Arrays.toString(mMargins)); + } + if (parent != null && parent.getMargin() != null) { + ext.put("parent.margin", parent.getMargin().toString()); + } + + if (mPaddings != null && mPaddings.length > 0) { + ext.put("child.padding", Arrays.toString(mPaddings)); + } + if (parent != null && parent.getPadding() != null) { + ext.put("parent.padding", parent.getPadding().toString()); + } + + if (mBorders != null && mBorders.length > 0) { + ext.put("child.border", Arrays.toString(mBorders)); + } + if (parent != null && parent.getBorder() != null) { + ext.put("parent.border", parent.getBorder().toString()); + } + + WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), + WXErrorCode.WX_RENDER_ERR_CONTAINER_TYPE, + "GraphicActionAddElement", + String.format(Locale.ENGLISH, "You are trying to add a %s to a %2$s, which is illegal as %2$s is not a container", + componentType, + WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef).getComponentType()), + ext); } - if (parent != null && parent.getStyles() != null && !parent.getStyles().isEmpty()) { - ext.put("parent.style", parent.getStyles().toString()); - } - - if (mAttributes != null && !mAttributes.isEmpty()) { - ext.put("child.attr", mAttributes.toString()); - } - if (parent != null && parent.getAttrs() != null && !parent.getAttrs().isEmpty()) { - ext.put("parent.attr", parent.getAttrs().toString()); - } - - if (mEvents != null && !mEvents.isEmpty()) { - ext.put("child.event", mEvents.toString()); - } - if (parent != null && parent.getEvents() != null && !parent.getEvents().isEmpty()) { - ext.put("parent.event", parent.getEvents().toString()); - } - - if (mMargins != null && mMargins.length > 0) { - ext.put("child.margin", Arrays.toString(mMargins)); - } - if (parent != null && parent.getMargin() != null) { - ext.put("parent.margin", parent.getMargin().toString()); - } - - if (mPaddings != null && mPaddings.length > 0) { - ext.put("child.padding", Arrays.toString(mPaddings)); - } - if (parent != null && parent.getPadding() != null) { - ext.put("parent.padding", parent.getPadding().toString()); - } - - if (mBorders != null && mBorders.length > 0) { - ext.put("child.border", Arrays.toString(mBorders)); - } - if (parent != null && parent.getBorder() != null) { - ext.put("parent.border", parent.getBorder().toString()); - } - - WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), - WXErrorCode.WX_RENDER_ERR_CONTAINER_TYPE, - "GraphicActionAddElement", - String.format(Locale.ENGLISH,"You are trying to add a %s to a %2$s, which is illegal as %2$s is not a container", - componentType, - WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef).getComponentType()), - ext); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java index fe1fa86f0a..b7e0e87e2d 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java @@ -21,7 +21,6 @@ import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.node.WXComponentNode; import java.util.Map; @@ -29,7 +28,6 @@ public class GraphicActionCreateBody extends GraphicActionAbstractAddElement { - private WXComponent component; private WXComponentNode node; public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, @@ -62,6 +60,5 @@ public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, public void executeAction() { super.executeAction(); node.createBody(); - } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java index 16935ad7b9..4f18265ccc 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java @@ -19,7 +19,6 @@ package com.taobao.weex.ui.action; import com.taobao.weex.WXSDKInstance; -import android.text.TextUtils; import com.taobao.weex.WXSDKManager; import com.taobao.weex.ui.component.node.WXComponentNode; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java index 82c4671c6f..f7c146600b 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java @@ -34,6 +34,7 @@ public class GraphicActionTransformNode extends BasicGraphicAction { public GraphicActionTransformNode(@NonNull WXComponentNode node, WXSDKInstance instance, String ref) { super(instance, ref); this.mNode = node; + this.mNode.createComponent(); } @Override diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java index f7ce602e84..2339647a28 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java @@ -29,6 +29,7 @@ import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; +import com.taobao.weex.bridge.WXBridgeManager; import com.taobao.weex.common.Constants; import com.taobao.weex.common.WXRenderStrategy; import com.taobao.weex.dom.WXStyle; @@ -51,7 +52,7 @@ /** * Created by luciolong on 14/07/2018. */ -public class WXComponentNode { +public class WXComponentNode implements Runnable { private static final String TAG = "WXComponentNode"; private static final int EXECUTE_STATE_CREATE_BODY = 1; @@ -120,12 +121,10 @@ public void startTransform() { } private void postTransformAction() { - new GraphicActionTransformNode(this, mWxInstance, mComponentData.mRef).executeActionOnRender(); + WXBridgeManager.getInstance().post(this); } public void transformNode() { - createComponent(); - switch (mExecuteState) { case EXECUTE_STATE_CREATE_BODY: createBody(); @@ -140,11 +139,11 @@ public void transformNode() { public void createComponent() { if (mWxInstance.getNeedInterceptRender()) { - mExecuteState = EXECUTE_STATE_CREATE_BODY; return; } if (data == null) { + WXLogUtils.d(TAG, "node real create component"); long createComponentStart = System.currentTimeMillis(); String pageId = mWxInstance.getInstanceId(); WXVContainer parent = null; @@ -181,12 +180,15 @@ public void createComponent() { public void createBody() { if (mWxInstance.getNeedInterceptRender()) { - mExecuteState = EXECUTE_STATE_ADD_ELEMENT; + mExecuteState = EXECUTE_STATE_CREATE_BODY; + mWxInstance.specifiedRootNode(this); return; } try { ensureDataNotNull(); if (data != null) { + WXLogUtils.d(TAG, "node real create body"); + data.mIsAddElementToTree = true; data.createView(); data.applyLayoutAndEvent(data); data.bindData(data); @@ -216,6 +218,7 @@ public void addElement() { } mParentNode.addNode(this, mIndex); if (mWxInstance.getNeedInterceptRender()) { + mExecuteState = EXECUTE_STATE_ADD_ELEMENT; return; } @@ -462,6 +465,11 @@ public WXSDKInstance getWxInstance() { return mWxInstance; } + @Override + public void run() { + new GraphicActionTransformNode(this, mWxInstance, mComponentData.mRef).executeActionOnRender(); + } + public void onCreateFinish() { if (mWxInstance.getNeedInterceptRender()) { return; From 4c66679ccf3b50de2a181b8b0ed398a28852a299 Mon Sep 17 00:00:00 2001 From: luciolong Date: Fri, 28 Dec 2018 16:37:02 +0800 Subject: [PATCH 04/13] [Android] weex prerender fix --- .../java/com/taobao/weex/ui/action/GraphicActionAddElement.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java index 417764da1e..eee7573e81 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java @@ -18,6 +18,7 @@ */ package com.taobao.weex.ui.action; +import android.support.annotation.NonNull; import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; import android.support.annotation.WorkerThread; From 8c7ba7e6af3b4be0b58b3ea0f96dadd2fc437c23 Mon Sep 17 00:00:00 2001 From: luciolong Date: Fri, 17 Aug 2018 15:13:11 +0800 Subject: [PATCH 05/13] [Android] weex prerender fix --- .../java/com/taobao/weex/WXSDKInstance.java | 5 +++++ .../taobao/weex/dom/action/TraceableAction.java | 0 .../taobao/weex/prerender/PreRenderContext.java | 3 +++ .../weex/prerender/WXPrerenderManager.java | 6 +++++- .../weex/ui/component/node/WXComponentNode.java | 17 +++++++++++++++++ .../weex/ui/config/ConfigComponentHolder.java | 5 +++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 android/sdk/src/main/java/com/taobao/weex/dom/action/TraceableAction.java diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java index 9cd25bbdd1..44a94fc20e 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java @@ -93,6 +93,7 @@ import java.util.Map; import java.util.PriorityQueue; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; /** @@ -299,6 +300,10 @@ public void specifiedRootNode(WXComponentNode rootNode) { mPrerenderContext.rootNode = rootNode; } + public AtomicBoolean isRenderSuccess() { + return mPrerenderContext.isRenderSuccess; + } + @NonNull public PreRenderContext getPrerenderContext() { return mPrerenderContext; diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/TraceableAction.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/TraceableAction.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java b/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java index 70de0e0996..38ab9175b4 100644 --- a/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java +++ b/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; /** @@ -45,4 +46,6 @@ public class PreRenderContext { public int width = 0; public int height = 0; + + public AtomicBoolean isRenderSuccess = new AtomicBoolean(false); } diff --git a/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java b/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java index b04062e351..73539b7eb6 100644 --- a/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java @@ -72,7 +72,11 @@ public WXSDKInstance preRenderByTemplate(Context context, String pageName, final @Nullable public WXSDKInstance fetchPreload(String url) { - return mPreloadInstanceMap.get(url); + WXSDKInstance instance = mPreloadInstanceMap.get(url); + if (instance != null) { + mPreloadInstanceMap.remove(url); + } + return instance; } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java index 2339647a28..cb093ed099 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java @@ -82,6 +82,8 @@ public class WXComponentNode implements Runnable { private boolean mIsLayoutRTL; private JSONObject mScrollOptions; + private boolean mIsRenderSuccuess = false; + private int mExecuteState = EXECUTE_STATE_ADD_ELEMENT; WXComponentNode(@NonNull BasicComponentData data, @@ -118,6 +120,7 @@ public void startTransform() { node.startTransform(); } } + mIsRenderSuccuess = true; } private void postTransformAction() { @@ -128,9 +131,23 @@ public void transformNode() { switch (mExecuteState) { case EXECUTE_STATE_CREATE_BODY: createBody(); + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + WXBridgeManager.getInstance().callCreateFinish(mWxInstance.getInstanceId()); + } + }); break; case EXECUTE_STATE_ADD_ELEMENT: addElement(); + if (mIsRenderSuccuess && mWxInstance.isRenderSuccess().compareAndSet(false, true)) { + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + WXBridgeManager.getInstance().callRenderSuccess(mWxInstance.getInstanceId()); + } + }); + } break; default: break; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java b/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java index 7a9948dac2..35e9e9a793 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java @@ -102,6 +102,11 @@ public synchronized Invoker getPropertyInvoker(String name){ return mPropertyInvokers.get(name); } + @Override + public String getComponentType() { + return mType; + } + @Override public Invoker getMethodInvoker(String name) { if(mMethodInvokers == null && !generate()){ From 08230f81cebaef75423ef133c1fbac776e57cd3b Mon Sep 17 00:00:00 2001 From: luciolong Date: Tue, 16 Oct 2018 11:55:10 +0800 Subject: [PATCH 06/13] [Android] weex prerender fix --- .../java/com/taobao/weex/WXSDKEngine.java | 14 ++++++++-- .../java/com/taobao/weex/WXSDKInstance.java | 3 +++ .../taobao/weex/bridge/WXBridgeManager.java | 2 +- .../weex/prerender/PreRenderContext.java | 26 ++++++++++++++++++- .../com/taobao/weex/ui/WXRenderManager.java | 1 + .../ui/component/node/WXComponentNode.java | 5 +++- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java index f528654eb9..439f904ada 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java @@ -319,14 +319,24 @@ private static void register() { new SimpleComponentHolder( WXCell.class, new WXCell.Creator() - ), + ) { + @Override + public String getComponentType() { + return WXBasicComponentType.CELL; + } + }, true, WXBasicComponentType.CELL); registerComponent( new SimpleComponentHolder( WXListComponent.class, new WXListComponent.Creator() - ), + ) { + @Override + public String getComponentType() { + return WXBasicComponentType.LIST; + } + }, true, WXBasicComponentType.LIST, WXBasicComponentType.VLIST, diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java index 44a94fc20e..75a10d0867 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java @@ -274,6 +274,7 @@ public void preRenderByUrl(String pageName, final String url, Map 0) { + int i = 0; for (WXComponentNode node : mChildNodes) { node.startTransform(); + node.setIndex(i); + i++; } } mIsRenderSuccuess = true; @@ -160,7 +163,7 @@ public void createComponent() { } if (data == null) { - WXLogUtils.d(TAG, "node real create component"); + WXLogUtils.d(TAG, "node real create component, type:" + mComponentData.mComponentType); long createComponentStart = System.currentTimeMillis(); String pageId = mWxInstance.getInstanceId(); WXVContainer parent = null; From c3b9cceee00bf2bed4f166135fea0c8c9002862b Mon Sep 17 00:00:00 2001 From: luciolong Date: Wed, 19 Dec 2018 17:42:46 +0800 Subject: [PATCH 07/13] =?UTF-8?q?[Android][prerender]=20=E5=8E=BB=E6=8E=89?= =?UTF-8?q?context=E9=99=90=E5=88=B6=EF=BC=8C=E9=81=BF=E5=85=8D=E9=A2=84?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E6=97=A0=E6=B3=95=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taobao/weex/ui/action/GraphicActionAddElement.java | 7 ++----- .../com/taobao/weex/ui/action/GraphicActionAddEvent.java | 2 +- .../taobao/weex/ui/action/GraphicActionCreateBody.java | 8 +++----- .../com/taobao/weex/ui/action/GraphicActionLayout.java | 2 +- .../taobao/weex/ui/action/GraphicActionRefreshFinish.java | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java index eee7573e81..9a3fac8754 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java @@ -65,12 +65,9 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, this.mMargins = margins; this.mBorders = borders; - if (instance.getContext() == null) { - return; + if (WXAnalyzerDataTransfer.isInteractionLogOpen()){ + Log.d(WXAnalyzerDataTransfer.INTERACTION_TAG, "[client][addelementStart]"+instance.getInstanceId()+","+componentType+","+ref); } - if (WXAnalyzerDataTransfer.isInteractionLogOpen()){ - Log.d(WXAnalyzerDataTransfer.INTERACTION_TAG, "[client][addelementStart]"+instance.getInstanceId()+","+componentType+","+ref); - } try { BasicComponentData basicComponentData = new BasicComponentData(ref, mComponentType, mParentRef); diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java index 2a50b0f054..290671d00a 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java @@ -38,7 +38,7 @@ public GraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { @Override public void executeAction() { WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); - if (instance == null || instance.getContext() == null) { + if (instance == null) { return; } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java index b7e0e87e2d..ca7076ff5b 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java @@ -47,10 +47,6 @@ public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, this.mPaddings = paddings; this.mBorders = borders; - if (instance.getContext() == null) { - return; - } - BasicComponentData basicComponentData = new BasicComponentData(getRef(), mComponentType, null); node = createNode(instance, basicComponentData).build(); node.createComponent(); @@ -59,6 +55,8 @@ public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, @Override public void executeAction() { super.executeAction(); - node.createBody(); + if (node != null) { + node.createBody(); + } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java index 71ab74b523..9a6bad3826 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java @@ -40,7 +40,7 @@ public GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition l @Override public void executeAction() { WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); - if (instance == null || instance.getContext() == null) { + if (instance == null) { WXLogUtils.w(WXLogUtils.WEEX_TAG); return; } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java index 0cc78bf090..1b04451441 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java @@ -44,7 +44,7 @@ public GraphicActionRefreshFinish(@NonNull WXSDKInstance instance) { @Override public void executeAction() { final WXSDKInstance instance = getWXSDKIntance(); - if (instance == null || instance.getContext() == null) { + if (instance == null) { return; } From dcf3f14f80ed79f4f9064f06b23fd5b304585f2e Mon Sep 17 00:00:00 2001 From: luciolong Date: Fri, 28 Dec 2018 17:03:36 +0800 Subject: [PATCH 08/13] [Android][prerender] rollback bridge log switch --- .../src/main/java/com/taobao/weex/bridge/WXBridgeManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java index 1ace446eb6..906664487f 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java @@ -194,7 +194,7 @@ public enum BundType { Others }; - private static final boolean BRIDGE_LOG_SWITCH = true; + private static final boolean BRIDGE_LOG_SWITCH = false; /** * Whether JS Framework(main.js) has been initialized. From c742447c992aba9dded60b1c3673720566eba23e Mon Sep 17 00:00:00 2001 From: luciolong Date: Sat, 22 Dec 2018 16:41:06 +0800 Subject: [PATCH 09/13] [Android][prerender] weex prerender bug fix --- .../java/com/taobao/weex/WXSDKInstance.java | 95 +++++++++++++++---- .../weex/prerender/PreRenderContext.java | 50 ++++++++++ .../weex/prerender/WXPrerenderManager.java | 30 +++++- .../ui/action/GraphicActionRenderSuccess.java | 1 - .../ui/component/node/WXComponentNode.java | 51 +++++++--- 5 files changed, 192 insertions(+), 35 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java index 75a10d0867..253a7477cd 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java @@ -142,11 +142,15 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan private WXInstanceApm mApmForInstance; private @NonNull FlatGUIContext mFlatGUIContext =new FlatGUIContext(); - @NonNull - private PreRenderContext mPrerenderContext = new PreRenderContext(); + + private float mRealWidth = 0; + private float mRealHeight = 0; private Map mContainerInfo; + @NonNull + private PreRenderContext mPrerenderContext = new PreRenderContext(); + public boolean isNewFsEnd = false; /** @@ -270,37 +274,66 @@ public void setUseSingleProcess(boolean flag) { WXBridgeManager.getInstance().setUseSingleProcess(flag); } - public void preRenderByUrl(String pageName, final String url, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + public void preRenderByUrl(String pageName, + final String url, + Map options, + final String jsonInitData, + final int width, + final int height, + final WXRenderStrategy flag, + final int layoutMode, final float offset) { if (mPrerenderContext.interceptRenderState.compareAndSet(PreRenderContext.INTERCEPT_RENDER_CLOSE, PreRenderContext.INTERCEPT_RENDER_OPEN)) { mPrerenderContext.width = width; mPrerenderContext.height = height; + mPrerenderContext.enableOffset = offset; + mPrerenderContext.setLayoutMode(layoutMode); mPrerenderContext.onPreRender(); renderByUrl(pageName, url, options, jsonInitData, flag); } } - public void preRenderByTemplate(String pageName, final String template, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + public void preRenderByTemplateWithLayoutMode(String pageName, + final String template, + Map options, + final String jsonInitData, + final int width, + final int height, + final WXRenderStrategy flag, + final int layoutMode, + final float offset) { if (mPrerenderContext.interceptRenderState.compareAndSet(PreRenderContext.INTERCEPT_RENDER_CLOSE, PreRenderContext.INTERCEPT_RENDER_OPEN)) { mPrerenderContext.width = width; mPrerenderContext.height = height; + mPrerenderContext.enableOffset = offset; + mPrerenderContext.setLayoutMode(layoutMode); mPrerenderContext.onPreRender(); render(pageName, template, options, jsonInitData, flag); } } - public void realRender(@NonNull Context context) { + public boolean realRender(@NonNull Context context) { if (mPrerenderContext.interceptRenderState.compareAndSet(PreRenderContext.INTERCEPT_RENDER_OPEN, PreRenderContext.INTERCEPT_RENDER_CLOSE)) { mContext = context; mPrerenderContext.onRealRender(); WXComponentNode rootNode = mPrerenderContext.rootNode; if (rootNode != null) { mPrerenderContext.rootNode.startTransform(); + return true; + } else { + WXLogUtils.w("real render failed, rootNode is null"); } + } else { + WXLogUtils.w("real render failed, state wrong"); } + return false; } public void specifiedRootNode(WXComponentNode rootNode) { - mPrerenderContext.rootNode = rootNode; + mPrerenderContext.rootNode = rootNode; + } + + public void updateRootNode() { + updateDefaultRootSize(mPrerenderContext.getRenderWidth(), mPrerenderContext.getRenderHeight()); } public AtomicBoolean isRenderSuccess() { @@ -1755,27 +1788,51 @@ public void setSize(int width, int height) { } ViewGroup.LayoutParams layoutParams = mRenderContainer.getLayoutParams(); if (layoutParams != null) { - final float realWidth = width; - final float realHeight = height; + + if (mRenderContainer.getWidth() != width || mRenderContainer.getHeight() != height) { layoutParams.width = width; layoutParams.height = height; mRenderContainer.setLayoutParams(layoutParams); } - if (mRootComp != null && layoutParams != null) { - final boolean isWidthWrapContent = layoutParams.width == ViewGroup.LayoutParams.WRAP_CONTENT; - final boolean isHeightWrapContent = layoutParams.height == ViewGroup.LayoutParams.WRAP_CONTENT; + updateDefaultRootSize(width, height); + } + } + } - WXBridgeManager.getInstance().post(new Runnable() { - @Override - public void run() { - WXBridgeManager.getInstance().setDefaultRootSize(getInstanceId(), realWidth, realHeight, isWidthWrapContent, - isHeightWrapContent); - } - }); + private void updateDefaultRootSize(final int width, final int height) { + // 预渲染中定下的宽高需要有个误差值,防止浮点的计算误差 + float offset = mPrerenderContext.enableOffset; + if (Math.abs(mRealWidth - width) < offset && Math.abs(mRealHeight - height) < offset) { + WXLogUtils.w("update default root size failed, size not changed"); + return; + } + int paramWidth = width; + int paramHeight = height; + + if (mRenderContainer != null && mRenderContainer.getLayoutParams() != null) { + paramWidth = mRenderContainer.getLayoutParams().width; + paramHeight = mRenderContainer.getLayoutParams().height; + } + + WXLogUtils.i("update default size, oldSize:(" + mRealWidth + ", " + mRealHeight + "), newSize:(" + width + ", " + height + ")"); + if (mRootComp != null || mPrerenderContext.rootNode != null) { + final boolean isWidthWrapContent = (paramWidth == ViewGroup.LayoutParams.WRAP_CONTENT); + final boolean isHeightWrapContent = (paramHeight == ViewGroup.LayoutParams.WRAP_CONTENT); + + final float realWidth = width; + final float realHeight = height; + mRealWidth = realWidth; + mRealHeight = realHeight; + + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + WXBridgeManager.getInstance().setDefaultRootSize(getInstanceId(), realWidth, realHeight, isWidthWrapContent, + isHeightWrapContent); } - } + }); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java b/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java index 87b48ed28f..ddf3018a05 100644 --- a/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java +++ b/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java @@ -20,6 +20,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.view.ViewGroup; import com.taobao.weex.WeexFrameRateControl; import com.taobao.weex.ui.component.node.WXComponentNode; @@ -36,10 +37,17 @@ public class PreRenderContext implements WeexFrameRateControl.VSyncListener { public static final int INTERCEPT_RENDER_CLOSE = 0; public static final int INTERCEPT_RENDER_OPEN = 1; + public static final int LAYOUT_MODE_SPECIFIC = 0; + public static final int LAYOUT_MODE_ADAPTIVE = 1; + public static final int LAYOUT_MODE_MATCH_PARENT = 2; + + public static final float DEFAULT_OFFSET = 0.00000001f; + // need intercept real render public AtomicInteger interceptRenderState = new AtomicInteger(INTERCEPT_RENDER_CLOSE); private WeexFrameRateControl mFrameRateControl; + private int mLayoutMode = LAYOUT_MODE_SPECIFIC; @Nullable public WXComponentNode rootNode; @@ -50,6 +58,8 @@ public class PreRenderContext implements WeexFrameRateControl.VSyncListener { public int width = 0; public int height = 0; + public float enableOffset = DEFAULT_OFFSET; + public AtomicBoolean isRenderSuccess = new AtomicBoolean(false); @Override @@ -66,10 +76,50 @@ public void onPreRender() { mFrameRateControl.start(); } + public void setLayoutMode(int layoutMode) { + switch (layoutMode) { + case LAYOUT_MODE_SPECIFIC: + if (width <= 0 || height <= 0) { + mLayoutMode = LAYOUT_MODE_ADAPTIVE; + break; + } + mLayoutMode = LAYOUT_MODE_SPECIFIC; + default: + mLayoutMode = layoutMode; + break; + } + } + + public int getLayoutMode() { + return mLayoutMode; + } + public void onRealRender() { if (mFrameRateControl != null) { mFrameRateControl.stop(); mFrameRateControl = null; } } + + public int getRenderWidth() { + switch (mLayoutMode) { + case LAYOUT_MODE_ADAPTIVE: + return ViewGroup.LayoutParams.WRAP_CONTENT; + case LAYOUT_MODE_MATCH_PARENT: + return ViewGroup.LayoutParams.MATCH_PARENT; + default: + return width; + } + } + + public int getRenderHeight() { + switch (mLayoutMode) { + case LAYOUT_MODE_ADAPTIVE: + return ViewGroup.LayoutParams.WRAP_CONTENT; + case LAYOUT_MODE_MATCH_PARENT: + return ViewGroup.LayoutParams.MATCH_PARENT; + default: + return height; + } + } } diff --git a/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java b/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java index 73539b7eb6..0fa449dc68 100644 --- a/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/prerender/WXPrerenderManager.java @@ -47,9 +47,22 @@ private WXPrerenderManager() { public WXSDKInstance preRenderByUrl(Context context, String pageName, final String url, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + return preRenderByUrl(context, pageName, url, options, jsonInitData, width, height, flag, PreRenderContext.LAYOUT_MODE_SPECIFIC, PreRenderContext.DEFAULT_OFFSET); + } + + public WXSDKInstance preRenderByUrl(Context context, String pageName, final String url, + Map options, final String jsonInitData, + final int width, final int height, final WXRenderStrategy flag, final int layoutMode) { + return preRenderByUrl(context, pageName, url, options, jsonInitData, width, height, flag, layoutMode, PreRenderContext.DEFAULT_OFFSET); + } + + public WXSDKInstance preRenderByUrl(Context context, String pageName, final String url, + Map options, final String jsonInitData, + final int width, final int height, final WXRenderStrategy flag, + final int layoutMode, final float offset) { if (!mPreloadInstanceMap.containsKey(url)) { WXSDKInstance instance = new WXSDKInstance(context); - instance.preRenderByUrl(pageName, url, options, jsonInitData, width, height, flag); + instance.preRenderByUrl(pageName, url, options, jsonInitData, width, height, flag, layoutMode, offset); mPreloadInstanceMap.put(url, instance); return instance; } else { @@ -60,9 +73,22 @@ public WXSDKInstance preRenderByUrl(Context context, String pageName, final Stri public WXSDKInstance preRenderByTemplate(Context context, String pageName, final String url, String template, Map options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) { + return preRenderByTemplate(context, pageName, url, template, options, jsonInitData, width, height, flag, PreRenderContext.LAYOUT_MODE_SPECIFIC, PreRenderContext.DEFAULT_OFFSET); + } + + public WXSDKInstance preRenderByTemplate(Context context, String pageName, final String url, + String template, Map options, final String jsonInitData, + final int width, final int height, final WXRenderStrategy flag, final int layoutMode) { + return preRenderByTemplate(context, pageName, url, template, options, jsonInitData, width, height, flag, layoutMode, PreRenderContext.DEFAULT_OFFSET); + } + + public WXSDKInstance preRenderByTemplate(Context context, String pageName, final String url, + String template, Map options, final String jsonInitData, + final int width, final int height, final WXRenderStrategy flag, + final int layoutMode, final float offset) { if (!mPreloadInstanceMap.containsKey(url)) { WXSDKInstance instance = new WXSDKInstance(context); - instance.preRenderByTemplate(pageName, template, options, jsonInitData, width, height, flag); + instance.preRenderByTemplateWithLayoutMode(pageName, template, options, jsonInitData, width, height, flag, layoutMode, offset); mPreloadInstanceMap.put(url, instance); return instance; } else { diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java index e6b7ebf165..7ec9ebdf0c 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java @@ -21,7 +21,6 @@ import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.node.WXComponentNode; public class GraphicActionRenderSuccess extends BasicGraphicAction { diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java index 21d1652c87..00c927a576 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java @@ -134,22 +134,13 @@ public void transformNode() { switch (mExecuteState) { case EXECUTE_STATE_CREATE_BODY: createBody(); - WXBridgeManager.getInstance().post(new Runnable() { - @Override - public void run() { - WXBridgeManager.getInstance().callCreateFinish(mWxInstance.getInstanceId()); - } - }); + mWxInstance.firstScreenCreateInstanceTime(System.currentTimeMillis()); + onCreateFinish(); break; case EXECUTE_STATE_ADD_ELEMENT: addElement(); if (mIsRenderSuccuess && mWxInstance.isRenderSuccess().compareAndSet(false, true)) { - WXBridgeManager.getInstance().post(new Runnable() { - @Override - public void run() { - WXBridgeManager.getInstance().callRenderSuccess(mWxInstance.getInstanceId()); - } - }); + onRenderSuccess(); } break; default: @@ -199,9 +190,10 @@ public void createComponent() { } public void createBody() { + mWxInstance.specifiedRootNode(this); if (mWxInstance.getNeedInterceptRender()) { mExecuteState = EXECUTE_STATE_CREATE_BODY; - mWxInstance.specifiedRootNode(this); + mWxInstance.updateRootNode(); return; } try { @@ -522,4 +514,37 @@ public void onRenderSuccess() { } mWxInstance.onRenderSuccess(layoutWidth, layoutHeight); } + + public void onRenderSuccess() { + if (mWxInstance.getNeedInterceptRender()) { + return; + } + + ensureDataNotNull(); + + int layoutWidth = 0; + int layoutHeight = 0; + if (null != data) { + layoutWidth = (int) data.getLayoutWidth(); + layoutHeight = (int) data.getLayoutHeight(); + } + mWxInstance.onRenderSuccess(layoutWidth, layoutHeight); + } + + public void onCreateFinish() { + if (mWxInstance.getNeedInterceptRender()) { + return; + } + + mWxInstance.mHasCreateFinish = true; + + if (mWxInstance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) { + mWxInstance.onCreateFinish(); + } + + if (null != mWxInstance.getWXPerformance()){ + mWxInstance.getWXPerformance().callCreateFinishTime = System.currentTimeMillis() - mWxInstance.getWXPerformance().renderTimeOrigin; + } + mWxInstance.onOldFsRenderTimeLogic(); + } } From 4ec046c70116499693aeaea1ba5665794a754f05 Mon Sep 17 00:00:00 2001 From: luciolong Date: Fri, 28 Dec 2018 17:12:22 +0800 Subject: [PATCH 10/13] [Android][prerender] conflict fix --- .../java/com/taobao/weex/WXSDKEngine.java | 14 ++------ .../ui/component/node/WXComponentNode.java | 32 ------------------- .../weex/ui/config/ConfigComponentHolder.java | 5 --- 3 files changed, 2 insertions(+), 49 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java index 439f904ada..f528654eb9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java @@ -319,24 +319,14 @@ private static void register() { new SimpleComponentHolder( WXCell.class, new WXCell.Creator() - ) { - @Override - public String getComponentType() { - return WXBasicComponentType.CELL; - } - }, + ), true, WXBasicComponentType.CELL); registerComponent( new SimpleComponentHolder( WXListComponent.class, new WXListComponent.Creator() - ) { - @Override - public String getComponentType() { - return WXBasicComponentType.LIST; - } - }, + ), true, WXBasicComponentType.LIST, WXBasicComponentType.VLIST, diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java index 00c927a576..8b8ecae6a7 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java @@ -515,36 +515,4 @@ public void onRenderSuccess() { mWxInstance.onRenderSuccess(layoutWidth, layoutHeight); } - public void onRenderSuccess() { - if (mWxInstance.getNeedInterceptRender()) { - return; - } - - ensureDataNotNull(); - - int layoutWidth = 0; - int layoutHeight = 0; - if (null != data) { - layoutWidth = (int) data.getLayoutWidth(); - layoutHeight = (int) data.getLayoutHeight(); - } - mWxInstance.onRenderSuccess(layoutWidth, layoutHeight); - } - - public void onCreateFinish() { - if (mWxInstance.getNeedInterceptRender()) { - return; - } - - mWxInstance.mHasCreateFinish = true; - - if (mWxInstance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) { - mWxInstance.onCreateFinish(); - } - - if (null != mWxInstance.getWXPerformance()){ - mWxInstance.getWXPerformance().callCreateFinishTime = System.currentTimeMillis() - mWxInstance.getWXPerformance().renderTimeOrigin; - } - mWxInstance.onOldFsRenderTimeLogic(); - } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java b/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java index 35e9e9a793..7a9948dac2 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/config/ConfigComponentHolder.java @@ -102,11 +102,6 @@ public synchronized Invoker getPropertyInvoker(String name){ return mPropertyInvokers.get(name); } - @Override - public String getComponentType() { - return mType; - } - @Override public Invoker getMethodInvoker(String name) { if(mMethodInvokers == null && !generate()){ From 4b8e47b5e27e36a09616d38728b3ca0f2ea61f8a Mon Sep 17 00:00:00 2001 From: luciolong Date: Mon, 7 Jan 2019 11:20:23 +0800 Subject: [PATCH 11/13] =?UTF-8?q?[Android][bugfix]=20fix=20storage=20?= =?UTF-8?q?=E5=BC=82=E6=AD=A5close=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appfram/storage/DefaultWXStorage.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java b/android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java index 28988480d2..3881dcfa07 100644 --- a/android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java +++ b/android/sdk/src/main/java/com/taobao/weex/appfram/storage/DefaultWXStorage.java @@ -143,15 +143,21 @@ public void run() { @Override public void close() { - try { - mDatabaseSupplier.closeDatabase(); - if (mExecutorService != null) { - mExecutorService.shutdown(); - mExecutorService = null; + final ExecutorService needCloseService = mExecutorService; + execute(new Runnable() { + @Override + public void run() { + try { + mDatabaseSupplier.closeDatabase(); + if (needCloseService != null) { + needCloseService.shutdown(); + } + } catch (Exception e) { + WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, e.getMessage()); + } } - } catch (Exception e) { - WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, e.getMessage()); - } + }); + mExecutorService = null; } private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) { From d73d4477db0024b7e02b73ade0bd72df430ba2d0 Mon Sep 17 00:00:00 2001 From: luciolong Date: Wed, 23 Jan 2019 15:02:00 +0800 Subject: [PATCH 12/13] [Android][prerender] refactoring prerender code --- .../com/taobao/weex/ui/IActionCreator.java | 25 ++ .../action/GraphicActionBaseAddElement.java | 8 + .../weex/ui/action/GraphicActionCreator.java | 8 + .../PrerenderActionCreator.java | 8 + .../PrerenderActionInvokeMethod.java | 53 ++++ ...renderGraphicActionAbstractAddElement.java | 87 ++++++ .../PrerenderGraphicActionAddElement.java | 173 +++++++++++ .../PrerenderGraphicActionAddEvent.java | 50 +++ .../PrerenderGraphicActionAnimation.java | 289 ++++++++++++++++++ .../PrerenderGraphicActionCreateBody.java | 62 ++++ .../PrerenderGraphicActionCreateFinish.java | 50 +++ .../PrerenderGraphicActionLayout.java | 53 ++++ .../PrerenderGraphicActionMoveElement.java | 44 +++ .../PrerenderGraphicActionRemoveElement.java | 38 +++ .../PrerenderGraphicActionRemoveEvent.java | 45 +++ .../PrerenderGraphicActionRenderSuccess.java | 44 +++ ...PrerenderGraphicActionScrollToElement.java | 45 +++ .../PrerenderGraphicActionTransformNode.java} | 0 .../PrerenderGraphicActionUpdateAttr.java | 50 +++ .../PrerenderGraphicActionUpdateStyle.java | 154 ++++++++++ 20 files changed, 1286 insertions(+) create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/IActionCreator.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionBaseAddElement.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreator.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionCreator.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionInvokeMethod.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAbstractAddElement.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddElement.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddEvent.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAnimation.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateBody.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateFinish.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionLayout.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionMoveElement.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveElement.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveEvent.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRenderSuccess.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionScrollToElement.java rename android/sdk/src/main/java/com/taobao/weex/ui/{action/GraphicActionTransformNode.java => prerenderaction/PrerenderGraphicActionTransformNode.java} (100%) create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateAttr.java create mode 100644 android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateStyle.java diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/IActionCreator.java b/android/sdk/src/main/java/com/taobao/weex/ui/IActionCreator.java new file mode 100644 index 0000000000..61d64c2873 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/IActionCreator.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui; + +/** + * Created by luciolong on 2019/1/23. + */ +public class IActionGenerator { +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionBaseAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionBaseAddElement.java new file mode 100644 index 0000000000..23ba0e81d3 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionBaseAddElement.java @@ -0,0 +1,8 @@ +package com.taobao.weex.ui.action; + +/** + * Description + * Created by luciolong on 2019/1/23. + */ +public class GraphicActionBaseAddElement { +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreator.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreator.java new file mode 100644 index 0000000000..6c4fa9702d --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreator.java @@ -0,0 +1,8 @@ +package com.taobao.weex.ui.action; + +/** + * Description + * Created by luciolong on 2019/1/23. + */ +public class GraphicActionCreator { +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionCreator.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionCreator.java new file mode 100644 index 0000000000..7aaae6bb06 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionCreator.java @@ -0,0 +1,8 @@ +package com.taobao.weex.ui.prerenderaction; + +/** + * Description + * Created by luciolong on 2019/1/23. + */ +public class PrerenderActionCreator { +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionInvokeMethod.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionInvokeMethod.java new file mode 100644 index 0000000000..9dff389fa9 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionInvokeMethod.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import com.alibaba.fastjson.JSONArray; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.utils.WXLogUtils; + +/** + * Created by listen on 18/01/10. + */ +public class ActionInvokeMethod implements IExecutable { + + private static final String TAG = "ActionInvokeMethod"; + + private final String mMethod; + private final JSONArray mArgs; + private String mPageId; + private String mRef; + + public ActionInvokeMethod(String pageId, String ref, String method, JSONArray args) { + this.mPageId = pageId; + this.mRef = ref; + this.mMethod = method; + this.mArgs = args; + } + + @Override + public void executeAction() { + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(mPageId, mRef); + if (node != null) { + node.invokeMethod(mMethod, mArgs); + } + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAbstractAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAbstractAddElement.java new file mode 100644 index 0000000000..44c0f91c02 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAbstractAddElement.java @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import android.support.annotation.NonNull; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.dom.CSSShorthand; +import com.taobao.weex.ui.component.node.WXComponentNodeBuilder; + +import java.util.Map; +import java.util.Set; + +public abstract class GraphicActionAbstractAddElement extends BasicGraphicAction { + + protected String mComponentType; + protected String mParentRef; + protected int mIndex = -1; + protected Map mStyle; + protected Map mAttributes; + protected Set mEvents; + protected float[] mMargins; + protected float[] mPaddings; + protected float[] mBorders; + private long startTime; + + public GraphicActionAbstractAddElement(WXSDKInstance instance, String ref) { + super(instance, ref); + startTime = System.currentTimeMillis(); + } + + protected WXComponentNodeBuilder createNode(WXSDKInstance instance, @NonNull BasicComponentData basicComponentData) { + basicComponentData.addStyle(mStyle); + basicComponentData.addAttr(mAttributes); + basicComponentData.addEvent(mEvents); + basicComponentData.addShorthand(mMargins, CSSShorthand.TYPE.MARGIN); + basicComponentData.addShorthand(mPaddings, CSSShorthand.TYPE.PADDING); + basicComponentData.addShorthand(mBorders, CSSShorthand.TYPE.BORDER); + + return WXComponentNodeBuilder.createInstance(instance, basicComponentData); + } + + @Override + public void executeAction() { + getWXSDKIntance().callActionAddElementTime(System.currentTimeMillis() - startTime); + } + + public String getComponentType() { + return mComponentType; + } + + public String getParentRef() { + return mParentRef; + } + + public int getIndex() { + return mIndex; + } + + public Map getStyle() { + return mStyle; + } + + public Map getAttributes() { + return mAttributes; + } + + public Set getEvents() { + return mEvents; + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddElement.java new file mode 100644 index 0000000000..9a3fac8754 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddElement.java @@ -0,0 +1,173 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import android.support.annotation.NonNull; +import android.support.annotation.RestrictTo; +import android.support.annotation.RestrictTo.Scope; +import android.support.annotation.WorkerThread; + +import android.support.v4.util.ArrayMap; +import android.util.Log; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.WXErrorCode; +import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.performance.WXAnalyzerDataTransfer; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.utils.WXExceptionUtils; + +import java.util.Arrays; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +public class GraphicActionAddElement extends GraphicActionAbstractAddElement { + + private GraphicPosition layoutPosition; + private GraphicSize layoutSize; + private boolean isLayoutRTL; + private WXComponentNode childNode; + + public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, + String componentType, String parentRef, + int index, + Map style, + Map attributes, + Set events, + float[] margins, + float[] paddings, + float[] borders) { + super(instance, ref); + this.mComponentType = componentType; + this.mParentRef = parentRef; + this.mIndex = index; + this.mStyle = style; + this.mAttributes = attributes; + this.mEvents = events; + this.mPaddings = paddings; + this.mMargins = margins; + this.mBorders = borders; + + if (WXAnalyzerDataTransfer.isInteractionLogOpen()){ + Log.d(WXAnalyzerDataTransfer.INTERACTION_TAG, "[client][addelementStart]"+instance.getInstanceId()+","+componentType+","+ref); + } + try { + BasicComponentData basicComponentData = new BasicComponentData(ref, mComponentType, + mParentRef); + childNode = createNode(instance, basicComponentData) + .setIndex(mIndex) + .setLayoutPosition(layoutPosition) + .setLayoutSize(layoutSize).build(); + childNode.createComponent(); + + } catch (ClassCastException e) { + Map ext = new ArrayMap<>(); + WXComponent parent = WXSDKManager.getInstance().getWXRenderManager() + .getWXComponent(getPageId(), mParentRef); + + if (parent != null) { + if (mStyle != null && !mStyle.isEmpty()) { + ext.put("child.style", mStyle.toString()); + } + if (parent != null && parent.getStyles() != null && !parent.getStyles().isEmpty()) { + ext.put("parent.style", parent.getStyles().toString()); + } + + if (mAttributes != null && !mAttributes.isEmpty()) { + ext.put("child.attr", mAttributes.toString()); + } + if (parent != null && parent.getAttrs() != null && !parent.getAttrs().isEmpty()) { + ext.put("parent.attr", parent.getAttrs().toString()); + } + + if (mEvents != null && !mEvents.isEmpty()) { + ext.put("child.event", mEvents.toString()); + } + if (parent != null && parent.getEvents() != null && !parent.getEvents().isEmpty()) { + ext.put("parent.event", parent.getEvents().toString()); + } + + if (mMargins != null && mMargins.length > 0) { + ext.put("child.margin", Arrays.toString(mMargins)); + } + if (parent != null && parent.getMargin() != null) { + ext.put("parent.margin", parent.getMargin().toString()); + } + + if (mPaddings != null && mPaddings.length > 0) { + ext.put("child.padding", Arrays.toString(mPaddings)); + } + if (parent != null && parent.getPadding() != null) { + ext.put("parent.padding", parent.getPadding().toString()); + } + + if (mBorders != null && mBorders.length > 0) { + ext.put("child.border", Arrays.toString(mBorders)); + } + if (parent != null && parent.getBorder() != null) { + ext.put("parent.border", parent.getBorder().toString()); + } + + WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), + WXErrorCode.WX_RENDER_ERR_CONTAINER_TYPE, + "GraphicActionAddElement", + String.format(Locale.ENGLISH, "You are trying to add a %s to a %2$s, which is illegal as %2$s is not a container", + componentType, + WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef).getComponentType()), + ext); + } + } + + } + + @RestrictTo(Scope.LIBRARY) + @WorkerThread + public void setRTL(boolean isRTL){ + isLayoutRTL = isRTL; + childNode.setIsLayoutRTL(isRTL); + } + + @RestrictTo(Scope.LIBRARY) + @WorkerThread + public void setSize(GraphicSize graphicSize){ + this.layoutSize = graphicSize; + childNode.setLayoutSize(graphicSize); + } + + @RestrictTo(Scope.LIBRARY) + @WorkerThread + public void setPosition(GraphicPosition position){ + this.layoutPosition = position; + childNode.setLayoutPosition(position); + } + + @RestrictTo(Scope.LIBRARY) + @WorkerThread + public void setIndex(int index){ + childNode.setIndex(index); + } + + @Override + public void executeAction() { + super.executeAction(); + childNode.setIsLayoutRTL(isLayoutRTL); + childNode.addElement(); + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddEvent.java new file mode 100644 index 0000000000..c555ffd587 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddEvent.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.prerenderaction; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.dom.WXEvent; +import com.taobao.weex.ui.component.node.WXComponentNode; + +/** + * Created by listen on 18/01/11. + */ +public class GraphicActionAddEvent extends BasicGraphicAction { + + private final String mEvent; + + public GraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { + super(instance, ref); + this.mEvent = WXEvent.getEventName(event); + } + + @Override + public void executeAction() { + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null) { + return; + } + + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.addEvent(mEvent); + } + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAnimation.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAnimation.java new file mode 100644 index 0000000000..4ac3add3ed --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAnimation.java @@ -0,0 +1,289 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ArgbEvaluator; +import android.animation.ObjectAnimator; +import android.animation.PropertyValuesHolder; +import android.graphics.drawable.ColorDrawable; +import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.view.animation.PathInterpolatorCompat; +import android.text.TextUtils; +import android.util.Pair; +import android.view.View; +import android.view.ViewGroup; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.DecelerateInterpolator; +import android.view.animation.Interpolator; +import android.view.animation.LinearInterpolator; + +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.Constants; +import com.taobao.weex.ui.animation.BackgroundColorProperty; +import com.taobao.weex.ui.animation.HeightProperty; +import com.taobao.weex.ui.animation.WXAnimationBean; +import com.taobao.weex.ui.animation.WXAnimationModule; +import com.taobao.weex.ui.animation.WidthProperty; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.list.template.TemplateDom; +import com.taobao.weex.ui.view.border.BorderDrawable; +import com.taobao.weex.utils.SingleFunctionParser; +import com.taobao.weex.utils.WXLogUtils; +import com.taobao.weex.utils.WXResourceUtils; +import com.taobao.weex.utils.WXUtils; +import com.taobao.weex.utils.WXViewUtils; + +import java.util.HashMap; +import java.util.List; + +public class GraphicActionAnimation extends BasicGraphicAction { + + private final static String TAG = "GraphicActionAnimation"; + + private final boolean styleNeedInit; + + @Nullable + private + final String callback; + + @Nullable + private + WXAnimationBean mAnimationBean; + + public GraphicActionAnimation(@NonNull WXSDKInstance instance, @NonNull String ref, @NonNull WXAnimationBean animationBean) { + super(instance, ref); + this.styleNeedInit = false; + this.callback = null; + this.mAnimationBean = animationBean; + } + + public GraphicActionAnimation(@NonNull WXSDKInstance instance, @NonNull String ref, @Nullable String animation, + @Nullable final String callBack) { + super(instance, ref); + this.styleNeedInit = true; + this.callback = callBack; + if (!TextUtils.isEmpty(animation)) { + this.mAnimationBean = JSONObject.parseObject(animation, WXAnimationBean.class); + } + } + public GraphicActionAnimation(@NonNull WXSDKInstance instance, @NonNull String ref, @NonNull WXAnimationBean animationBean, + @Nullable final String callBack) { + super(instance, ref); + this.styleNeedInit = false; + this.mAnimationBean = animationBean; + this.callback = callBack; + } + + @Override + public void executeAction() { + if (null == mAnimationBean) { + return; + } + + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + if(!TemplateDom.isVirtualDomRef(getRef())){ + return; + } + component = TemplateDom.findVirtualComponentByVRef(getPageId(), getRef()); + if(component == null){ + return; + } + } + + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null || instance.getNeedInterceptRender()) { + return; + } + + if (null != mAnimationBean.styles) { + if(styleNeedInit) { + // Synchronize transformOrigin between component styles and animation style before + // animation start. + String transformOrigin = (String) component.getStyles().get(Constants.Name.TRANSFORM_ORIGIN); + if (TextUtils.isEmpty(mAnimationBean.styles.transformOrigin)) { + mAnimationBean.styles.transformOrigin = transformOrigin; + } + mAnimationBean.styles.init(mAnimationBean.styles.transformOrigin, + mAnimationBean.styles.transform, (int) component.getLayoutWidth(), + (int) component.getLayoutHeight(), + instance.getInstanceViewPortWidth(), instance); + } + startAnimation(instance, component); + } + } + + + + private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) { + if (component != null) { + if (mAnimationBean != null) { + component.setNeedLayoutOnAnimation(mAnimationBean.needLayout); + } + if (component.getHostView() == null) { + WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean, callback); + component.postAnimation(holder); + } else { + try { + Animator animator = createAnimator(component.getHostView(), instance + .getInstanceViewPortWidth()); + if (animator != null) { + Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && component + .isLayerTypeEnabled() ) { + component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null); + } + Interpolator interpolator = createTimeInterpolator(); + if (animatorCallback != null) { + animator.addListener(animatorCallback); + } + if (interpolator != null) { + animator.setInterpolator(interpolator); + } + component.getHostView().setCameraDistance(mAnimationBean.styles.getCameraDistance()); + animator.setDuration(mAnimationBean.duration); + animator.start(); + } + } catch (RuntimeException e) { + WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e)); + } + } + } + } + + private + @Nullable + ObjectAnimator createAnimator(final View target, final int viewPortWidth) { + if (target == null) { + return null; + } + WXAnimationBean.Style style = mAnimationBean.styles; + if (style != null) { + ObjectAnimator animator; + List holders = style.getHolders(); + if (!TextUtils.isEmpty(style.backgroundColor)) { + BorderDrawable borderDrawable; + if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) { + holders.add(PropertyValuesHolder.ofObject( + new BackgroundColorProperty(), new ArgbEvaluator(), + borderDrawable.getColor(), + WXResourceUtils.getColor(style.backgroundColor))); + } else if (target.getBackground() instanceof ColorDrawable) { + holders.add(PropertyValuesHolder.ofObject( + new BackgroundColorProperty(), new ArgbEvaluator(), + ((ColorDrawable) target.getBackground()).getColor(), + WXResourceUtils.getColor(style.backgroundColor))); + } + } + + if (target.getLayoutParams() != null && + (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) { + ViewGroup.LayoutParams layoutParams = target.getLayoutParams(); + if (!TextUtils.isEmpty(style.width)) { + holders.add(PropertyValuesHolder.ofInt(new WidthProperty(), layoutParams.width, + (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth))); + } + if (!TextUtils.isEmpty(style.height)) { + holders.add(PropertyValuesHolder.ofInt(new HeightProperty(), layoutParams.height, + (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth))); + } + } + + if (style.getPivot() != null) { + Pair pair = style.getPivot(); + target.setPivotX(pair.first); + target.setPivotY(pair.second); + } + animator = ObjectAnimator.ofPropertyValuesHolder( + target, holders.toArray(new PropertyValuesHolder[holders.size()])); + animator.setStartDelay(mAnimationBean.delay); + return animator; + } else { + return null; + } + } + + private + @Nullable + Animator.AnimatorListener createAnimatorListener(final WXSDKInstance instance, @Nullable final String callBack) { + if (!TextUtils.isEmpty(callBack)) { + return new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + if (instance == null || instance.isDestroy()) { + WXLogUtils.e("RenderContextImpl-onAnimationEnd WXSDKInstance == null NPE or instance is destroyed"); + } else { + WXSDKManager.getInstance().callback(instance.getInstanceId(), + callBack, + new HashMap()); + } + } + }; + } else { + return null; + } + } + + private + @Nullable + Interpolator createTimeInterpolator() { + String interpolator = mAnimationBean.timingFunction; + if (!TextUtils.isEmpty(interpolator)) { + switch (interpolator) { + case WXAnimationBean.EASE_IN: + return new AccelerateInterpolator(); + case WXAnimationBean.EASE_OUT: + return new DecelerateInterpolator(); + case WXAnimationBean.EASE_IN_OUT: + return new AccelerateDecelerateInterpolator(); + case WXAnimationBean.LINEAR: + return new LinearInterpolator(); + default: + //Parse cubic-bezier + try { + SingleFunctionParser parser = new SingleFunctionParser<>( + mAnimationBean.timingFunction, + new SingleFunctionParser.FlatMapper() { + @Override + public Float map(String raw) { + return Float.parseFloat(raw); + } + }); + List params = parser.parse(WXAnimationBean.CUBIC_BEZIER); + if (params != null && params.size() == WXAnimationBean.NUM_CUBIC_PARAM) { + return PathInterpolatorCompat.create( + params.get(0), params.get(1), params.get(2), params.get(3)); + } else { + return null; + } + } catch (RuntimeException e) { + return null; + } + } + } + return null; + } +} \ No newline at end of file diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateBody.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateBody.java new file mode 100644 index 0000000000..ca7076ff5b --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateBody.java @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import android.support.annotation.NonNull; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.component.node.WXComponentNode; + +import java.util.Map; +import java.util.Set; + +public class GraphicActionCreateBody extends GraphicActionAbstractAddElement { + + private WXComponentNode node; + + public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, + String componentType, + Map style, + Map attributes, + Set events, + float[] margins, + float[] paddings, + float[] borders) { + super(instance, ref); + this.mComponentType = componentType; + this.mStyle = style; + this.mAttributes = attributes; + this.mEvents = events; + this.mMargins = margins; + this.mPaddings = paddings; + this.mBorders = borders; + + BasicComponentData basicComponentData = new BasicComponentData(getRef(), mComponentType, null); + node = createNode(instance, basicComponentData).build(); + node.createComponent(); + } + + @Override + public void executeAction() { + super.executeAction(); + if (node != null) { + node.createBody(); + } + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateFinish.java new file mode 100644 index 0000000000..039643c0fe --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateFinish.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import android.support.annotation.NonNull; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.performance.WXInstanceApm; + +/** + * Created by listen on 18/01/09. + */ +public class GraphicActionCreateFinish extends BasicGraphicAction { + + public GraphicActionCreateFinish(@NonNull WXSDKInstance instance) { + super(instance, ""); + instance.getApmForInstance().onStage(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH); + instance.getApmForInstance().extInfo.put(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH,true); + + } + + @Override + public void executeAction() { + final WXSDKInstance instance = getWXSDKIntance(); + if (instance == null) { + return; + } + + if (instance.getPrerenderContext().rootNode != null) { + instance.getPrerenderContext().rootNode.onCreateFinish(); + } + + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionLayout.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionLayout.java new file mode 100644 index 0000000000..9a6bad3826 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionLayout.java @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.utils.WXLogUtils; + +public class GraphicActionLayout extends BasicGraphicAction { + + private final GraphicPosition mLayoutPosition; + private final GraphicSize mLayoutSize; + private final boolean mIsLayoutRTL; + + public GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition layoutPosition, GraphicSize layoutSize, boolean isRTL) { + super(instance, ref); + this.mLayoutPosition = layoutPosition; + this.mLayoutSize = layoutSize; + this.mIsLayoutRTL = isRTL; + } + + @Override + public void executeAction() { + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null) { + WXLogUtils.w(WXLogUtils.WEEX_TAG); + return; + } + + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.updateLayout(mLayoutPosition, mLayoutSize, mIsLayoutRTL); + } + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionMoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionMoveElement.java new file mode 100644 index 0000000000..4f18265ccc --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionMoveElement.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import com.taobao.weex.WXSDKInstance; + +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.node.WXComponentNode; + +public class GraphicActionMoveElement extends BasicGraphicAction { + + private String mParentref; + private int mIndex; + + public GraphicActionMoveElement(WXSDKInstance instance, String ref, String parentRef, int index) { + super(instance, ref); + this.mParentref = parentRef; + this.mIndex = index; + } + + @Override + public void executeAction() { + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.moveElement(mParentref, mIndex); + } + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveElement.java new file mode 100644 index 0000000000..01191d96d9 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveElement.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.node.WXComponentNode; + +public class GraphicActionRemoveElement extends BasicGraphicAction { + + public GraphicActionRemoveElement(WXSDKInstance instance, String ref) { + super(instance, ref); + } + + @Override + public void executeAction() { + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.removeElement(); + } + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveEvent.java new file mode 100644 index 0000000000..e52d3e832a --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveEvent.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.dom.WXEvent; +import com.taobao.weex.ui.component.node.WXComponentNode; + +/** + * Created by listen on 18/01/11. + */ +public class GraphicActionRemoveEvent extends BasicGraphicAction { + + private final String mEvent; + + public GraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event) { + super(instance, ref); + this.mEvent = WXEvent.getEventName(event); + } + + @Override + public void executeAction() { + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.removeEvent(mEvent); + } + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRenderSuccess.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRenderSuccess.java new file mode 100644 index 0000000000..7ec9ebdf0c --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRenderSuccess.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import android.support.annotation.NonNull; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.component.node.WXComponentNode; + +public class GraphicActionRenderSuccess extends BasicGraphicAction { + + public GraphicActionRenderSuccess(@NonNull WXSDKInstance instance) { + super(instance, ""); + } + + @Override + public void executeAction() { + final WXSDKInstance instance = getWXSDKIntance(); + if (instance == null) { + return; + } + WXComponentNode rootNode = instance.getPrerenderContext().rootNode; + if (rootNode != null) { + rootNode.onRenderSuccess(); + } + } + +} \ No newline at end of file diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionScrollToElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionScrollToElement.java new file mode 100644 index 0000000000..c9f0a36d4d --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionScrollToElement.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.node.WXComponentNode; + +/** + * Created by listen on 18/01/09. + */ +public class GraphicActionScrollToElement extends BasicGraphicAction { + + private final JSONObject mOptions; + + public GraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObject options) { + super(instance, ref); + this.mOptions = options; + } + + @Override + public void executeAction() { + WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (node != null) { + node.scrollToElement(mOptions); + } + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionTransformNode.java similarity index 100% rename from android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionTransformNode.java rename to android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionTransformNode.java diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateAttr.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateAttr.java new file mode 100644 index 0000000000..828d5f9662 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateAttr.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.node.WXComponentNode; + +import java.util.Map; + +public class GraphicActionUpdateAttr extends BasicGraphicAction { + + private Map mAttrs; + private WXComponentNode mNode; + + public GraphicActionUpdateAttr(WXSDKInstance instance, String ref, + Map attrs) { + super(instance, ref); + this.mAttrs = attrs; + + mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (mNode != null) { + mNode.addAttrs(mAttrs); + } + } + + @Override + public void executeAction() { + if (mNode == null) { + return; + } + mNode.updateAttrs(mAttrs); + } +} diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateStyle.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateStyle.java new file mode 100644 index 0000000000..0bd05e3d28 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateStyle.java @@ -0,0 +1,154 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.taobao.weex.ui.action; + +import android.support.v4.util.ArrayMap; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.bridge.WXBridgeManager; +import com.taobao.weex.common.Constants; +import com.taobao.weex.dom.CSSShorthand; +import com.taobao.weex.dom.transition.WXTransition; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; + +import java.util.Map; + +public class GraphicActionUpdateStyle extends BasicGraphicAction { + + private Map mStyle; + private WXComponentNode mNode; + private boolean mIsCausedByPesudo; + private boolean mIsBorderSet; + + public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, + Map style, + Map paddings, + Map margins, + Map borders) { + this(instance, ref, style, paddings, margins, borders, false); + } + + public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, + Map style, + CSSShorthand paddings, + CSSShorthand margins, + CSSShorthand borders, boolean byPesudo) { + super(instance, ref); + this.mStyle = style; + this.mIsCausedByPesudo = byPesudo; + + mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (mNode == null) { + return; + } + if (null != mStyle) { + mNode.getComponentData().getStyles().updateStyle(mStyle, mIsCausedByPesudo); + if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { + if (style.containsKey(Constants.Name.TRANSFORM) && mNode.data.getTransition() == null) { + Map animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap + .put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + mNode.data.addAnimationForElement(animationMap); + } + } + } + + if (null != paddings) { + mNode.getComponentData().setPaddings(paddings); + } + + if (null != margins) { + mNode.getComponentData().setMargins(margins); + } + + if (null != borders) { + mIsBorderSet = true; + mNode.getComponentData().setBorders(borders); + } + } + + public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, + Map style, + Map paddings, + Map margins, + Map borders, boolean byPesudo) { + super(instance, ref); + this.mStyle = style; + this.mIsCausedByPesudo = byPesudo; + + mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (mNode == null) { + return; + } + if (null != mStyle) { + mNode.getComponentData().addStyle(mStyle, mIsCausedByPesudo); + if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { + if (style.containsKey(Constants.Name.TRANSFORM) && mNode.data.getTransition() == null) { + Map animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap.put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + mNode.data.addAnimationForElement(animationMap); + WXBridgeManager.getInstance().markDirty(getPageId(), getRef(), true); + } + } + } + + if (null != paddings) { + mNode.getComponentData().addShorthand(paddings); + } + + if (null != margins) { + mNode.getComponentData().addShorthand(margins); + } + + if (null != borders) { + mIsBorderSet = true; + mNode.getComponentData().addShorthand(borders); + } + } + + @Override + public void executeAction() { // need merge + mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); + if (mNode == null) { + return; + } + + if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { + WXComponent component = mNode.data; + if (mStyle != null) { + if (component.getTransition() != null) { + component.getTransition().updateTranstionParams(mStyle); + if (component.getTransition().hasTransitionProperty(mStyle)) { + component.getTransition().startTransition(mStyle); + } + } else { + component.setTransition(WXTransition.fromMap(mStyle, component)); + component.updateStyles(mStyle); + } + } else if (mIsBorderSet) { + component.updateStyles(component); + } + } + } +} + From 6838a161470ee695f31f6f483aaf71bd042cb03a Mon Sep 17 00:00:00 2001 From: luciolong Date: Wed, 23 Jan 2019 15:05:50 +0800 Subject: [PATCH 13/13] [Android][prerender] refactoring prerender code --- .../java/com/taobao/weex/WXSDKInstance.java | 11 +- .../taobao/weex/bridge/WXBridgeManager.java | 47 ++-- .../taobao/weex/common/WXRenderStrategy.java | 1 + .../weex/prerender/PreRenderContext.java | 7 + .../com/taobao/weex/ui/IActionCreator.java | 69 ++++- .../weex/ui/action/ActionInvokeMethod.java | 11 +- .../GraphicActionAbstractAddElement.java | 42 ++- .../ui/action/GraphicActionAddElement.java | 157 ++++++----- .../weex/ui/action/GraphicActionAddEvent.java | 17 +- .../ui/action/GraphicActionAnimation.java | 2 +- .../action/GraphicActionBaseAddElement.java | 53 +++- .../ui/action/GraphicActionCreateBody.java | 44 ++- .../ui/action/GraphicActionCreateFinish.java | 26 +- .../weex/ui/action/GraphicActionCreator.java | 133 ++++++++- .../weex/ui/action/GraphicActionLayout.java | 17 +- .../ui/action/GraphicActionMoveElement.java | 36 ++- .../ui/action/GraphicActionRefreshFinish.java | 2 +- .../ui/action/GraphicActionRemoveElement.java | 38 ++- .../ui/action/GraphicActionRemoveEvent.java | 15 +- .../ui/action/GraphicActionRenderSuccess.java | 16 +- .../action/GraphicActionScrollToElement.java | 17 +- .../ui/action/GraphicActionUpdateAttr.java | 20 +- .../ui/action/GraphicActionUpdateStyle.java | 88 +++--- .../ui/action/UpdateComponentDataAction.java | 1 - .../weex/ui/animation/WXAnimationModule.java | 4 +- .../ui/component/node/WXComponentNode.java | 4 +- .../taobao/weex/ui/module/WXDomModule.java | 12 +- .../PrerenderActionCreator.java | 119 +++++++- .../PrerenderActionInvokeMethod.java | 11 +- ...renderGraphicActionAbstractAddElement.java | 8 +- .../PrerenderGraphicActionAddElement.java | 35 ++- .../PrerenderGraphicActionAddEvent.java | 5 +- .../PrerenderGraphicActionAnimation.java | 256 +----------------- .../PrerenderGraphicActionCreateBody.java | 21 +- .../PrerenderGraphicActionCreateFinish.java | 7 +- .../PrerenderGraphicActionLayout.java | 10 +- .../PrerenderGraphicActionMoveElement.java | 8 +- .../PrerenderGraphicActionRemoveElement.java | 7 +- .../PrerenderGraphicActionRemoveEvent.java | 7 +- .../PrerenderGraphicActionRenderSuccess.java | 7 +- ...PrerenderGraphicActionScrollToElement.java | 7 +- .../PrerenderGraphicActionTransformNode.java | 7 +- .../PrerenderGraphicActionUpdateAttr.java | 9 +- .../PrerenderGraphicActionUpdateStyle.java | 35 +-- 44 files changed, 886 insertions(+), 563 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java index 986cae4e74..ec53b9c082 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java @@ -71,6 +71,7 @@ import com.taobao.weex.prerender.PreRenderContext; import com.taobao.weex.tracing.WXTracing; import com.taobao.weex.ui.action.GraphicActionAddElement; +import com.taobao.weex.ui.action.GraphicActionBaseAddElement; import com.taobao.weex.ui.component.NestedContainer; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXEmbed; @@ -216,7 +217,7 @@ public void removeLayerOverFlowListener(String ref) { private boolean mCurrentGround = false; private ComponentObserver mComponentObserver; - private Map inactiveAddElementAction = new ArrayMap<>(); + private Map inactiveAddElementAction = new ArrayMap<>(); private Map mContentBoxMeasurements = new ArrayMap<>(); @@ -377,7 +378,7 @@ public void setMaxHiddenEmbedsNum(int maxHiddenEmbedsNum) { @WorkerThread @RestrictTo(Scope.LIBRARY) - public void addInActiveAddElementAction(String ref, GraphicActionAddElement action){ + public void addInActiveAddElementAction(String ref, GraphicActionBaseAddElement action){ inactiveAddElementAction.put(ref, action); } @@ -389,7 +390,7 @@ public void removeInActiveAddElmentAction(String ref){ @WorkerThread @RestrictTo(Scope.LIBRARY) - public GraphicActionAddElement getInActiveAddElementAction(String ref){ + public GraphicActionBaseAddElement getInActiveAddElementAction(String ref){ return inactiveAddElementAction.get(ref); } @@ -2148,4 +2149,8 @@ public void addInstanceOnFireEventInterceptor(InstanceOnFireEventInterceptor ins getInstanceOnFireEventInterceptorList().add(instanceOnFireEventInterceptor); } } + + public boolean hasPrerender() { + return mPrerenderContext.isPrerenderMode(); + } } diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java index 792c0e79ac..3010ec5862 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java @@ -58,14 +58,13 @@ import com.taobao.weex.dom.CSSShorthand; import com.taobao.weex.layout.ContentBoxMeasurement; import com.taobao.weex.performance.WXInstanceApm; +import com.taobao.weex.ui.IActionCreator; import com.taobao.weex.ui.WXComponentRegistry; import com.taobao.weex.ui.action.ActionReloadPage; import com.taobao.weex.ui.action.BasicGraphicAction; -import com.taobao.weex.ui.action.GraphicActionAddElement; -import com.taobao.weex.ui.action.GraphicActionAddEvent; import com.taobao.weex.ui.action.GraphicActionAppendTreeCreateFinish; -import com.taobao.weex.ui.action.GraphicActionCreateBody; -import com.taobao.weex.ui.action.GraphicActionCreateFinish; +import com.taobao.weex.ui.action.GraphicActionBaseAddElement; +import com.taobao.weex.ui.action.GraphicActionCreator; import com.taobao.weex.ui.action.GraphicActionLayout; import com.taobao.weex.ui.action.GraphicActionMoveElement; import com.taobao.weex.ui.action.GraphicActionRefreshFinish; @@ -78,6 +77,7 @@ import com.taobao.weex.ui.action.GraphicSize; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.module.WXDomModule; +import com.taobao.weex.ui.prerenderaction.PrerenderActionCreator; import com.taobao.weex.utils.WXExceptionUtils; import com.taobao.weex.utils.WXFileUtils; import com.taobao.weex.utils.WXJsonUtils; @@ -206,6 +206,9 @@ public enum BundType { private static Map mWeexCoreEnvOptions = new HashMap<>(); + private IActionCreator mPrerenderCreator = new PrerenderActionCreator(); + private IActionCreator mNormalCreator = new GraphicActionCreator(); + /** * package **/ @@ -2456,7 +2459,7 @@ public int callCreateBody(String pageId, String componentType, String ref, try { WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(pageId); if (instance != null) { - final BasicGraphicAction action = new GraphicActionCreateBody(instance, ref, componentType, + final BasicGraphicAction action = getActionCreator(instance).createGraphicActionCreateBody(instance, ref, componentType, styles, attributes, events, margins, paddings, borders); WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(action.getPageId(), action); } @@ -2501,8 +2504,10 @@ public int callAddElement(String pageId, String componentType, String ref, int i try { WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(pageId); if (instance != null) { - final GraphicActionAddElement action = new GraphicActionAddElement(instance, ref, componentType, parentRef, index, - styles, attributes, events, margins, paddings, borders); + final GraphicActionBaseAddElement action = getActionCreator(instance) + .createGraphicActionAddElement(instance, + ref, componentType, parentRef, index, + styles, attributes, events, margins, paddings, borders); if(willLayout) { instance.addInActiveAddElementAction(ref, action); }else{ @@ -2545,7 +2550,7 @@ public int callRemoveElement(String instanceId, String ref) { try { WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId); if (instance != null) { - final BasicGraphicAction action = new GraphicActionRemoveElement(instance, ref); + final BasicGraphicAction action = getActionCreator(instance).createGraphicActionRemoveElement(instance, ref); if(instance.getInActiveAddElementAction(ref)!=null){ instance.removeInActiveAddElmentAction(ref); } @@ -2592,7 +2597,7 @@ public int callMoveElement(String instanceId, String ref, String parentref, int try { WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId); if (instance != null) { - final BasicGraphicAction action = new GraphicActionMoveElement(instance, ref, parentref, index); + final BasicGraphicAction action = getActionCreator(instance).createGraphicActionMoveElement(instance, ref, parentref, index); WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(action.getPageId(), action); } } catch (Exception e) { @@ -2632,7 +2637,7 @@ public int callAddEvent(String instanceId, String ref, String event) { try { WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId); if (instance != null) { - new GraphicActionAddEvent(instance, ref, event).executeActionOnRender(); + getActionCreator(instance).createGraphicActionAddEvent(instance, ref, event).executeActionOnRender(); } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callAddEvent exception: ", e); @@ -2673,7 +2678,7 @@ public int callRemoveEvent(String instanceId, String ref, String event) { try { WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId); if (instance != null) { - new GraphicActionRemoveEvent(instance, ref, event).executeActionOnRender(); + getActionCreator(instance).createGraphicActionRemoveEvent(instance, ref, event).executeActionOnRender(); } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callRemoveEvent exception: ", e); @@ -2720,7 +2725,7 @@ public int callUpdateStyle(String instanceId, String ref, HashMap entry : mWeexCoreEnvOptions.entrySet()) { mWXBridge.registerCoreEnv(entry.getKey(), entry.getValue()); diff --git a/android/sdk/src/main/java/com/taobao/weex/common/WXRenderStrategy.java b/android/sdk/src/main/java/com/taobao/weex/common/WXRenderStrategy.java index 36ef8aa528..b4f7c29b31 100644 --- a/android/sdk/src/main/java/com/taobao/weex/common/WXRenderStrategy.java +++ b/android/sdk/src/main/java/com/taobao/weex/common/WXRenderStrategy.java @@ -24,6 +24,7 @@ public enum WXRenderStrategy { DATA_RENDER("DATA_RENDER"), DATA_RENDER_BINARY("DATA_RENDER_BINARY"); + private String flag; WXRenderStrategy(String flag) { diff --git a/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java b/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java index ddf3018a05..d50bdbac59 100644 --- a/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java +++ b/android/sdk/src/main/java/com/taobao/weex/prerender/PreRenderContext.java @@ -62,6 +62,8 @@ public class PreRenderContext implements WeexFrameRateControl.VSyncListener { public AtomicBoolean isRenderSuccess = new AtomicBoolean(false); + private boolean mIsPrerenderMode = false; + @Override public void OnVSync() { if (rootNode != null) { @@ -74,6 +76,7 @@ public void onPreRender() { mFrameRateControl = new WeexFrameRateControl(this); } mFrameRateControl.start(); + mIsPrerenderMode = true; } public void setLayoutMode(int layoutMode) { @@ -122,4 +125,8 @@ public int getRenderHeight() { return height; } } + + public boolean isPrerenderMode() { + return mIsPrerenderMode; + } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/IActionCreator.java b/android/sdk/src/main/java/com/taobao/weex/ui/IActionCreator.java index 61d64c2873..3dd3c539de 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/IActionCreator.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/IActionCreator.java @@ -18,8 +18,75 @@ */ package com.taobao.weex.ui; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.action.BasicGraphicAction; +import com.taobao.weex.ui.action.GraphicActionBaseAddElement; +import com.taobao.weex.ui.action.GraphicPosition; +import com.taobao.weex.ui.action.GraphicSize; +import com.taobao.weex.ui.action.IExecutable; + +import java.util.Map; +import java.util.Set; + /** * Created by luciolong on 2019/1/23. */ -public class IActionGenerator { +public interface IActionCreator { + GraphicActionBaseAddElement createGraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, + String componentType, String parentRef, + int index, + Map style, + Map attributes, + Set events, + float[] margins, + float[] paddings, + float[] borders); + + BasicGraphicAction createGraphicActionLayout(WXSDKInstance instance, + String ref, + GraphicPosition layoutPosition, + GraphicSize layoutSize, + boolean isRTL); + + IExecutable createActionInvokeMethod(String pageId, String ref, String method, JSONArray args); + + BasicGraphicAction createGraphicActionAddEvent(WXSDKInstance instance, String ref, Object event); + + BasicGraphicAction createGraphicActionAnimation(@NonNull WXSDKInstance instance, @NonNull String ref, @Nullable String animation, + @Nullable final String callBack); + + BasicGraphicAction createGraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, + String componentType, + Map style, + Map attributes, + Set events, + float[] margins, + float[] paddings, + float[] borders); + + BasicGraphicAction createGraphicActionCreateFinish(@NonNull WXSDKInstance instance); + + BasicGraphicAction createGraphicActionMoveElement(WXSDKInstance instance, String ref, String parentRef, int index); + + BasicGraphicAction createGraphicActionRemoveElement(WXSDKInstance instance, String ref); + + BasicGraphicAction createGraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event); + + BasicGraphicAction createGraphicActionRenderSuccess(@NonNull WXSDKInstance instance); + + BasicGraphicAction createGraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObject options); + + BasicGraphicAction createGraphicActionUpdateAttr(WXSDKInstance instance, String ref, + Map attrs); + + BasicGraphicAction createGraphicActionUpdateStyle(WXSDKInstance instance, String ref, + Map style, + Map paddings, + Map margins, + Map borders); } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java index 9dff389fa9..2b387cec50 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java @@ -21,7 +21,6 @@ import com.alibaba.fastjson.JSONArray; import com.taobao.weex.WXSDKManager; import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.node.WXComponentNode; import com.taobao.weex.utils.WXLogUtils; /** @@ -36,7 +35,7 @@ public class ActionInvokeMethod implements IExecutable { private String mPageId; private String mRef; - public ActionInvokeMethod(String pageId, String ref, String method, JSONArray args) { + ActionInvokeMethod(String pageId, String ref, String method, JSONArray args) { this.mPageId = pageId; this.mRef = ref; this.mMethod = method; @@ -45,9 +44,11 @@ public ActionInvokeMethod(String pageId, String ref, String method, JSONArray ar @Override public void executeAction() { - WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(mPageId, mRef); - if (node != null) { - node.invokeMethod(mMethod, mArgs); + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(mPageId, mRef); + if(component == null){ + WXLogUtils.e(TAG,"target component not found."); + return; } + component.invoke(mMethod,mArgs); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java index 44c0f91c02..f593da1e19 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java @@ -18,16 +18,18 @@ */ package com.taobao.weex.ui.action; -import android.support.annotation.NonNull; - +import android.support.v4.util.ArrayMap; import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.Constants; import com.taobao.weex.dom.CSSShorthand; -import com.taobao.weex.ui.component.node.WXComponentNodeBuilder; - +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXComponentFactory; +import com.taobao.weex.ui.component.WXVContainer; import java.util.Map; import java.util.Set; -public abstract class GraphicActionAbstractAddElement extends BasicGraphicAction { +public abstract class GraphicActionAbstractAddElement extends GraphicActionBaseAddElement { protected String mComponentType; protected String mParentRef; @@ -45,15 +47,28 @@ public GraphicActionAbstractAddElement(WXSDKInstance instance, String ref) { startTime = System.currentTimeMillis(); } - protected WXComponentNodeBuilder createNode(WXSDKInstance instance, @NonNull BasicComponentData basicComponentData) { - basicComponentData.addStyle(mStyle); - basicComponentData.addAttr(mAttributes); - basicComponentData.addEvent(mEvents); - basicComponentData.addShorthand(mMargins, CSSShorthand.TYPE.MARGIN); - basicComponentData.addShorthand(mPaddings, CSSShorthand.TYPE.PADDING); - basicComponentData.addShorthand(mBorders, CSSShorthand.TYPE.BORDER); + protected WXComponent createComponent(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) { + long createComponentStart = System.currentTimeMillis(); + if (basicComponentData != null) { + basicComponentData.addStyle(mStyle); + basicComponentData.addAttr(mAttributes); + basicComponentData.addEvent(mEvents); + basicComponentData.addShorthand(mMargins, CSSShorthand.TYPE.MARGIN); + basicComponentData.addShorthand(mPaddings, CSSShorthand.TYPE.PADDING); + basicComponentData.addShorthand(mBorders, CSSShorthand.TYPE.BORDER); + } - return WXComponentNodeBuilder.createInstance(instance, basicComponentData); + WXComponent component = WXComponentFactory.newInstance(instance, parent, basicComponentData); + WXSDKManager.getInstance().getWXRenderManager().registerComponent(getPageId(), getRef(), component); + if(mStyle != null && mStyle.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null) { + Map animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, mStyle.get(Constants.Name.TRANSFORM)); + animationMap + .put(Constants.Name.TRANSFORM_ORIGIN, mStyle.get(Constants.Name.TRANSFORM_ORIGIN)); + component.addAnimationForElement(animationMap); + } + instance.onComponentCreate(component,System.currentTimeMillis() -createComponentStart); + return component; } @Override @@ -84,4 +99,5 @@ public Map getAttributes() { public Set getEvents() { return mEvents; } + } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java index 9a3fac8754..0cc15769c3 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java @@ -22,17 +22,18 @@ import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; import android.support.annotation.WorkerThread; - import android.support.v4.util.ArrayMap; +import android.text.TextUtils; import android.util.Log; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.common.WXErrorCode; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.dom.transition.WXTransition; import com.taobao.weex.performance.WXAnalyzerDataTransfer; import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXVContainer; import com.taobao.weex.utils.WXExceptionUtils; - +import com.taobao.weex.utils.WXLogUtils; import java.util.Arrays; import java.util.Locale; import java.util.Map; @@ -40,12 +41,13 @@ public class GraphicActionAddElement extends GraphicActionAbstractAddElement { + private WXVContainer parent; + private WXComponent child; private GraphicPosition layoutPosition; private GraphicSize layoutSize; private boolean isLayoutRTL; - private WXComponentNode childNode; - public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, + GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, String componentType, String parentRef, int index, Map style, @@ -65,109 +67,136 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, this.mMargins = margins; this.mBorders = borders; - if (WXAnalyzerDataTransfer.isInteractionLogOpen()){ - Log.d(WXAnalyzerDataTransfer.INTERACTION_TAG, "[client][addelementStart]"+instance.getInstanceId()+","+componentType+","+ref); + if (instance.getContext() == null) { + return; } + if (WXAnalyzerDataTransfer.isInteractionLogOpen()){ + Log.d(WXAnalyzerDataTransfer.INTERACTION_TAG, "[client][addelementStart]"+instance.getInstanceId()+","+componentType+","+ref); + } try { + parent = (WXVContainer) WXSDKManager.getInstance().getWXRenderManager() + .getWXComponent(getPageId(), mParentRef); BasicComponentData basicComponentData = new BasicComponentData(ref, mComponentType, mParentRef); - childNode = createNode(instance, basicComponentData) - .setIndex(mIndex) - .setLayoutPosition(layoutPosition) - .setLayoutSize(layoutSize).build(); - childNode.createComponent(); + child = createComponent(instance, parent, basicComponentData); + child.setTransition(WXTransition.fromMap(child.getStyles(), child)); + if (null != parent && parent.isIgnoreInteraction){ + child.isIgnoreInteraction = true; + } + if (!child.isIgnoreInteraction ){ + Object flag = null; + if (null != child.getAttrs()){ + flag = child.getAttrs().get("ignoreInteraction"); + } + if ("1".equals(flag) || "true".equals(flag) || child.isFixed()){ + child.isIgnoreInteraction = true; + } + } } catch (ClassCastException e) { Map ext = new ArrayMap<>(); WXComponent parent = WXSDKManager.getInstance().getWXRenderManager() .getWXComponent(getPageId(), mParentRef); - if (parent != null) { - if (mStyle != null && !mStyle.isEmpty()) { - ext.put("child.style", mStyle.toString()); - } - if (parent != null && parent.getStyles() != null && !parent.getStyles().isEmpty()) { - ext.put("parent.style", parent.getStyles().toString()); - } - - if (mAttributes != null && !mAttributes.isEmpty()) { - ext.put("child.attr", mAttributes.toString()); - } - if (parent != null && parent.getAttrs() != null && !parent.getAttrs().isEmpty()) { - ext.put("parent.attr", parent.getAttrs().toString()); - } + if (mStyle != null && !mStyle.isEmpty()) { + ext.put("child.style", mStyle.toString()); + } + if (parent != null && parent.getStyles() != null && !parent.getStyles().isEmpty()) { + ext.put("parent.style", parent.getStyles().toString()); + } - if (mEvents != null && !mEvents.isEmpty()) { - ext.put("child.event", mEvents.toString()); - } - if (parent != null && parent.getEvents() != null && !parent.getEvents().isEmpty()) { - ext.put("parent.event", parent.getEvents().toString()); - } + if (mAttributes != null && !mAttributes.isEmpty()) { + ext.put("child.attr", mAttributes.toString()); + } + if (parent != null && parent.getAttrs() != null && !parent.getAttrs().isEmpty()) { + ext.put("parent.attr", parent.getAttrs().toString()); + } - if (mMargins != null && mMargins.length > 0) { - ext.put("child.margin", Arrays.toString(mMargins)); - } - if (parent != null && parent.getMargin() != null) { - ext.put("parent.margin", parent.getMargin().toString()); - } + if (mEvents != null && !mEvents.isEmpty()) { + ext.put("child.event", mEvents.toString()); + } + if (parent != null && parent.getEvents() != null && !parent.getEvents().isEmpty()) { + ext.put("parent.event", parent.getEvents().toString()); + } - if (mPaddings != null && mPaddings.length > 0) { - ext.put("child.padding", Arrays.toString(mPaddings)); - } - if (parent != null && parent.getPadding() != null) { - ext.put("parent.padding", parent.getPadding().toString()); - } + if (mMargins != null && mMargins.length > 0) { + ext.put("child.margin", Arrays.toString(mMargins)); + } + if (parent != null && parent.getMargin() != null) { + ext.put("parent.margin", parent.getMargin().toString()); + } - if (mBorders != null && mBorders.length > 0) { - ext.put("child.border", Arrays.toString(mBorders)); - } - if (parent != null && parent.getBorder() != null) { - ext.put("parent.border", parent.getBorder().toString()); - } + if (mPaddings != null && mPaddings.length > 0) { + ext.put("child.padding", Arrays.toString(mPaddings)); + } + if (parent != null && parent.getPadding() != null) { + ext.put("parent.padding", parent.getPadding().toString()); + } - WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), - WXErrorCode.WX_RENDER_ERR_CONTAINER_TYPE, - "GraphicActionAddElement", - String.format(Locale.ENGLISH, "You are trying to add a %s to a %2$s, which is illegal as %2$s is not a container", - componentType, - WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef).getComponentType()), - ext); + if (mBorders != null && mBorders.length > 0) { + ext.put("child.border", Arrays.toString(mBorders)); + } + if (parent != null && parent.getBorder() != null) { + ext.put("parent.border", parent.getBorder().toString()); } + + WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), + WXErrorCode.WX_RENDER_ERR_CONTAINER_TYPE, + "GraphicActionAddElement", + String.format(Locale.ENGLISH,"You are trying to add a %s to a %2$s, which is illegal as %2$s is not a container", + componentType, + WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef).getComponentType()), + ext); } } @RestrictTo(Scope.LIBRARY) @WorkerThread + @Override public void setRTL(boolean isRTL){ - isLayoutRTL = isRTL; - childNode.setIsLayoutRTL(isRTL); + this.isLayoutRTL = isRTL; } @RestrictTo(Scope.LIBRARY) @WorkerThread + @Override public void setSize(GraphicSize graphicSize){ this.layoutSize = graphicSize; - childNode.setLayoutSize(graphicSize); } @RestrictTo(Scope.LIBRARY) @WorkerThread + @Override public void setPosition(GraphicPosition position){ this.layoutPosition = position; - childNode.setLayoutPosition(position); } @RestrictTo(Scope.LIBRARY) @WorkerThread + @Override public void setIndex(int index){ - childNode.setIndex(index); + mIndex = index; } @Override public void executeAction() { super.executeAction(); - childNode.setIsLayoutRTL(isLayoutRTL); - childNode.addElement(); + try { + if (!TextUtils.equals(mComponentType, "video") && !TextUtils.equals(mComponentType, "videoplus")) + child.mIsAddElementToTree = true; + + parent.addChild(child, mIndex); + parent.createChildViewAt(mIndex); + + child.setIsLayoutRTL(isLayoutRTL); + if(layoutPosition !=null && layoutSize != null) { + child.setDemission(layoutSize, layoutPosition); + } + child.applyLayoutAndEvent(child); + child.bindData(child); + } catch (Exception e) { + WXLogUtils.e("add component failed.", e); + } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java index 290671d00a..ed7d23e587 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java @@ -21,7 +21,8 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.dom.WXEvent; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.tracing.Stopwatch; +import com.taobao.weex.ui.component.WXComponent; /** * Created by listen on 18/01/11. @@ -30,21 +31,23 @@ public class GraphicActionAddEvent extends BasicGraphicAction { private final String mEvent; - public GraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { + GraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { super(instance, ref); this.mEvent = WXEvent.getEventName(event); } @Override public void executeAction() { - WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); - if (instance == null) { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { return; } - WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (node != null) { - node.addEvent(mEvent); + Stopwatch.tick(); + if (!component.getEvents().contains(mEvent)) { + component.getEvents().addEvent(mEvent); } + component.addEvent(mEvent); + Stopwatch.split("addEventToComponent"); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java index 4ac3add3ed..4023b0c232 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java @@ -115,7 +115,7 @@ public void executeAction() { } WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); - if (instance == null || instance.getNeedInterceptRender()) { + if (instance == null) { return; } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionBaseAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionBaseAddElement.java index 23ba0e81d3..984ca22c84 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionBaseAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionBaseAddElement.java @@ -1,8 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package com.taobao.weex.ui.action; +import android.support.annotation.RestrictTo; +import android.support.annotation.WorkerThread; + +import com.taobao.weex.WXSDKInstance; + /** - * Description * Created by luciolong on 2019/1/23. */ -public class GraphicActionBaseAddElement { +public abstract class GraphicActionBaseAddElement extends BasicGraphicAction { + public GraphicActionBaseAddElement(WXSDKInstance instance, String ref) { + super(instance, ref); + } + + @RestrictTo(RestrictTo.Scope.LIBRARY) + @WorkerThread + public void setRTL(boolean isRTL) { + // empty + } + + @RestrictTo(RestrictTo.Scope.LIBRARY) + @WorkerThread + public void setSize(GraphicSize graphicSize) { + // empty + } + + @RestrictTo(RestrictTo.Scope.LIBRARY) + @WorkerThread + public void setPosition(GraphicPosition position) { + // empty + } + + @RestrictTo(RestrictTo.Scope.LIBRARY) + @WorkerThread + public void setIndex(int index) { + // empty + } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java index ca7076ff5b..b162e0d940 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java @@ -19,18 +19,23 @@ package com.taobao.weex.ui.action; import android.support.annotation.NonNull; +import android.widget.ScrollView; import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.common.WXRenderStrategy; +import com.taobao.weex.dom.transition.WXTransition; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXScroller; +import com.taobao.weex.utils.WXLogUtils; import java.util.Map; import java.util.Set; public class GraphicActionCreateBody extends GraphicActionAbstractAddElement { - private WXComponentNode node; + private WXComponent component; - public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, + GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, String componentType, Map style, Map attributes, @@ -47,16 +52,41 @@ public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, this.mPaddings = paddings; this.mBorders = borders; + if (instance.getContext() == null) { + return; + } + BasicComponentData basicComponentData = new BasicComponentData(getRef(), mComponentType, null); - node = createNode(instance, basicComponentData).build(); - node.createComponent(); + component = createComponent(instance, null, basicComponentData); + if (component == null) { + return; + } + component.setTransition(WXTransition.fromMap(component.getStyles(), component)); } @Override public void executeAction() { super.executeAction(); - if (node != null) { - node.createBody(); + try { + component.createView(); + component.applyLayoutAndEvent(component); + component.bindData(component); + WXSDKInstance instance = getWXSDKIntance(); + + if (component instanceof WXScroller) { + WXScroller scroller = (WXScroller) component; + if (scroller.getInnerView() instanceof ScrollView) { + instance.setRootScrollView((ScrollView) scroller.getInnerView()); + } + } + + instance.onRootCreated(component); + + if (instance.getRenderStrategy() != WXRenderStrategy.APPEND_ONCE) { + instance.onCreateFinish(); + } + } catch (Exception e) { + WXLogUtils.e("create body failed.", e); } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java index 039643c0fe..1621a7ad24 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java @@ -21,30 +21,46 @@ import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.WXRenderStrategy; import com.taobao.weex.performance.WXInstanceApm; +import com.taobao.weex.ui.component.WXComponent; /** * Created by listen on 18/01/09. */ public class GraphicActionCreateFinish extends BasicGraphicAction { - public GraphicActionCreateFinish(@NonNull WXSDKInstance instance) { + private int mLayoutWidth; + private int mLayoutHeight; + + GraphicActionCreateFinish(@NonNull WXSDKInstance instance) { super(instance, ""); + WXComponent component = instance.getRootComponent(); + if (null != component) { + this.mLayoutWidth = (int) component.getLayoutWidth(); + this.mLayoutHeight = (int) component.getLayoutHeight(); + } instance.getApmForInstance().onStage(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH); instance.getApmForInstance().extInfo.put(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH,true); - } @Override public void executeAction() { final WXSDKInstance instance = getWXSDKIntance(); - if (instance == null) { + if (instance == null || instance.getContext() == null) { return; } - if (instance.getPrerenderContext().rootNode != null) { - instance.getPrerenderContext().rootNode.onCreateFinish(); + instance.mHasCreateFinish = true; + + if (instance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) { + instance.onCreateFinish(); } + if (null != instance.getWXPerformance()){ + instance.getWXPerformance().callCreateFinishTime = System.currentTimeMillis()-instance.getWXPerformance().renderTimeOrigin; + } + instance.onOldFsRenderTimeLogic(); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreator.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreator.java index 6c4fa9702d..f0f8f7c978 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreator.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreator.java @@ -1,8 +1,137 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package com.taobao.weex.ui.action; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.IActionCreator; + +import java.util.Map; +import java.util.Set; + /** - * Description * Created by luciolong on 2019/1/23. */ -public class GraphicActionCreator { +public class GraphicActionCreator implements IActionCreator { + @Override + public GraphicActionBaseAddElement createGraphicActionAddElement(@NonNull WXSDKInstance instance, + String ref, + String componentType, + String parentRef, + int index, + Map style, + Map attributes, + Set events, float[] margins, + float[] paddings, + float[] borders) { + return new GraphicActionAddElement(instance, + ref, componentType, parentRef, + index, style, attributes, events, + margins, paddings, borders); + } + + @Override + public BasicGraphicAction createGraphicActionLayout(WXSDKInstance instance, + String ref, + GraphicPosition layoutPosition, + GraphicSize layoutSize, + boolean isRTL) { + return new GraphicActionLayout(instance, ref, layoutPosition, layoutSize, isRTL); + } + + @Override + public IExecutable createActionInvokeMethod(String pageId, String ref, String method, JSONArray args) { + return new ActionInvokeMethod(pageId, ref, method, args); + } + + @Override + public BasicGraphicAction createGraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { + return new GraphicActionAddEvent(instance, ref,event); + } + + @Override + public BasicGraphicAction createGraphicActionAnimation(@NonNull WXSDKInstance instance, + @NonNull String ref, + @Nullable String animation, + @Nullable String callBack) { + return new GraphicActionAnimation(instance, ref, animation, callBack); + } + + @Override + public BasicGraphicAction createGraphicActionCreateBody(@NonNull WXSDKInstance instance, + String ref, + String componentType, + Map style, + Map attributes, + Set events, + float[] margins, + float[] paddings, + float[] borders) { + return new GraphicActionCreateBody(instance, ref, componentType, style, attributes, events, margins, paddings, borders); + } + + @Override + public BasicGraphicAction createGraphicActionCreateFinish(@NonNull WXSDKInstance instance) { + return new GraphicActionCreateFinish(instance); + } + + @Override + public BasicGraphicAction createGraphicActionMoveElement(WXSDKInstance instance, String ref, String parentRef, int index) { + return new GraphicActionMoveElement(instance, ref, parentRef, index); + } + + @Override + public BasicGraphicAction createGraphicActionRemoveElement(WXSDKInstance instance, String ref) { + return new GraphicActionRemoveElement(instance, ref); + } + + @Override + public BasicGraphicAction createGraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event) { + return new GraphicActionRemoveEvent(instance, ref, event); + } + + @Override + public BasicGraphicAction createGraphicActionRenderSuccess(@NonNull WXSDKInstance instance) { + return new GraphicActionRenderSuccess(instance); + } + + @Override + public BasicGraphicAction createGraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObject options) { + return new GraphicActionScrollToElement(instance, ref, options); + } + + @Override + public BasicGraphicAction createGraphicActionUpdateAttr(WXSDKInstance instance, String ref, Map attrs) { + return new GraphicActionUpdateAttr(instance, ref, attrs); + } + + @Override + public BasicGraphicAction createGraphicActionUpdateStyle(WXSDKInstance instance, + String ref, + Map style, + Map paddings, + Map margins, + Map borders) { + return new GraphicActionUpdateStyle(instance, ref, style, paddings, margins, borders); + } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java index 9a6bad3826..e8e362325e 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java @@ -21,8 +21,6 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.node.WXComponentNode; -import com.taobao.weex.utils.WXLogUtils; public class GraphicActionLayout extends BasicGraphicAction { @@ -30,7 +28,7 @@ public class GraphicActionLayout extends BasicGraphicAction { private final GraphicSize mLayoutSize; private final boolean mIsLayoutRTL; - public GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition layoutPosition, GraphicSize layoutSize, boolean isRTL) { + GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition layoutPosition, GraphicSize layoutSize, boolean isRTL) { super(instance, ref); this.mLayoutPosition = layoutPosition; this.mLayoutSize = layoutSize; @@ -39,15 +37,14 @@ public GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition l @Override public void executeAction() { - WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); - if (instance == null) { - WXLogUtils.w(WXLogUtils.WEEX_TAG); + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { return; } - WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (node != null) { - node.updateLayout(mLayoutPosition, mLayoutSize, mIsLayoutRTL); - } + component.setIsLayoutRTL(mIsLayoutRTL); + component.setDemission(mLayoutSize, mLayoutPosition); + component.setSafeLayout(component); + component.setPadding(component.getPadding(), component.getBorder()); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java index 4f18265ccc..393a9a2b22 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java @@ -19,16 +19,18 @@ package com.taobao.weex.ui.action; import com.taobao.weex.WXSDKInstance; +import android.text.TextUtils; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXVContainer; public class GraphicActionMoveElement extends BasicGraphicAction { private String mParentref; private int mIndex; - public GraphicActionMoveElement(WXSDKInstance instance, String ref, String parentRef, int index) { + GraphicActionMoveElement(WXSDKInstance instance, String ref, String parentRef, int index) { super(instance, ref); this.mParentref = parentRef; this.mIndex = index; @@ -36,9 +38,33 @@ public GraphicActionMoveElement(WXSDKInstance instance, String ref, String paren @Override public void executeAction() { - WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (node != null) { - node.moveElement(mParentref, mIndex); + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if(component == null) { + return; + } + WXVContainer oldParent = component.getParent(); + WXComponent newParent = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentref); + if (oldParent == null + || newParent == null || !(newParent instanceof WXVContainer)) { + return; + } + + if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) { + int[] location = new int[2] ; + component.getHostView().getLocationInWindow(location); + } + + oldParent.remove(component, false); + + ((WXVContainer) newParent).addChild(component, mIndex); + + if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) { + int[] location = new int[2] ; + component.getHostView().getLocationInWindow(location); + } + + if (!component.isVirtualComponent()) { + ((WXVContainer) newParent).addSubView(component.getHostView(), mIndex); } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java index 1b04451441..0cc78bf090 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java @@ -44,7 +44,7 @@ public GraphicActionRefreshFinish(@NonNull WXSDKInstance instance) { @Override public void executeAction() { final WXSDKInstance instance = getWXSDKIntance(); - if (instance == null) { + if (instance == null || instance.getContext() == null) { return; } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java index 01191d96d9..91febda830 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java @@ -18,21 +18,49 @@ */ package com.taobao.weex.ui.action; +import android.text.TextUtils; + import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXVContainer; public class GraphicActionRemoveElement extends BasicGraphicAction { - public GraphicActionRemoveElement(WXSDKInstance instance, String ref) { + GraphicActionRemoveElement(WXSDKInstance instance, String ref) { super(instance, ref); } @Override public void executeAction() { - WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (node != null) { - node.removeElement(); + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null || component.getParent() == null || component.getInstance() == null) { + return; + } + clearRegistryForComponent(component); + WXVContainer parent = component.getParent(); + + if (component.getHostView() != null && !TextUtils.equals(component.getComponentType(), "video") && !TextUtils.equals(component.getComponentType(), "videoplus")) { + int[] location = new int[2]; + component.getHostView().getLocationInWindow(location); + //component.getInstance().onChangeElement(parent, location[1] > component.getInstance().getWeexHeight() + 1); + } + + parent.remove(component, true); + } + + private void clearRegistryForComponent(WXComponent component) { + WXComponent removedComponent = WXSDKManager.getInstance().getWXRenderManager().unregisterComponent(getPageId(), getRef()); + if (removedComponent != null) { + removedComponent.removeAllEvent(); + removedComponent.removeStickyStyle(); + } + if (component instanceof WXVContainer) { + WXVContainer container = (WXVContainer) component; + int count = container.childCount(); + for (int i = count - 1; i >= 0; --i) { + clearRegistryForComponent(container.getChild(i)); + } } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java index e52d3e832a..c0e13a51aa 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java @@ -21,7 +21,8 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.dom.WXEvent; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.tracing.Stopwatch; +import com.taobao.weex.ui.component.WXComponent; /** * Created by listen on 18/01/11. @@ -30,16 +31,20 @@ public class GraphicActionRemoveEvent extends BasicGraphicAction { private final String mEvent; - public GraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event) { + GraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event) { super(instance, ref); this.mEvent = WXEvent.getEventName(event); } @Override public void executeAction() { - WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (node != null) { - node.removeEvent(mEvent); + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; } + + Stopwatch.tick(); + component.removeEvent(mEvent); + Stopwatch.split("removeEventFromComponent"); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java index 7ec9ebdf0c..b82a68988b 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRenderSuccess.java @@ -21,24 +21,28 @@ import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.ui.component.WXComponent; public class GraphicActionRenderSuccess extends BasicGraphicAction { - public GraphicActionRenderSuccess(@NonNull WXSDKInstance instance) { + GraphicActionRenderSuccess(@NonNull WXSDKInstance instance) { super(instance, ""); } @Override public void executeAction() { final WXSDKInstance instance = getWXSDKIntance(); - if (instance == null) { + if (instance == null || instance.getContext() == null) { return; } - WXComponentNode rootNode = instance.getPrerenderContext().rootNode; - if (rootNode != null) { - rootNode.onRenderSuccess(); + WXComponent component = instance.getRootComponent(); + int layoutWidth = 0; + int layoutHeight = 0; + if (null != component) { + layoutWidth = (int) component.getLayoutWidth(); + layoutHeight = (int) component.getLayoutHeight(); } + instance.onRenderSuccess(layoutWidth, layoutHeight); } } \ No newline at end of file diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java index c9f0a36d4d..6c5937a6ff 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java @@ -21,7 +21,8 @@ import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.ui.component.Scrollable; +import com.taobao.weex.ui.component.WXComponent; /** * Created by listen on 18/01/09. @@ -30,16 +31,22 @@ public class GraphicActionScrollToElement extends BasicGraphicAction { private final JSONObject mOptions; - public GraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObject options) { + GraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObject options) { super(instance, ref); this.mOptions = options; } @Override public void executeAction() { - WXComponentNode node = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (node != null) { - node.scrollToElement(mOptions); + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; } + + Scrollable scroller = component.getParentScroller(); + if (scroller == null) { + return; + } + scroller.scrollTo(component, mOptions); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java index 828d5f9662..69a6134c1d 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java @@ -20,31 +20,35 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.node.WXComponentNode; +import com.taobao.weex.ui.component.WXComponent; import java.util.Map; public class GraphicActionUpdateAttr extends BasicGraphicAction { private Map mAttrs; - private WXComponentNode mNode; + private WXComponent component; - public GraphicActionUpdateAttr(WXSDKInstance instance, String ref, + GraphicActionUpdateAttr(WXSDKInstance instance, String ref, Map attrs) { super(instance, ref); this.mAttrs = attrs; - mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (mNode != null) { - mNode.addAttrs(mAttrs); + component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + if (mAttrs != null) { + component.addAttr(mAttrs); } } @Override public void executeAction() { - if (mNode == null) { + if (component == null) { return; } - mNode.updateAttrs(mAttrs); + component.getAttrs().mergeAttr(); + component.updateAttrs(mAttrs); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java index 0bd05e3d28..e7a484802d 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java @@ -27,18 +27,17 @@ import com.taobao.weex.dom.CSSShorthand; import com.taobao.weex.dom.transition.WXTransition; import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.node.WXComponentNode; import java.util.Map; public class GraphicActionUpdateStyle extends BasicGraphicAction { private Map mStyle; - private WXComponentNode mNode; + private WXComponent component; private boolean mIsCausedByPesudo; private boolean mIsBorderSet; - public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, + GraphicActionUpdateStyle(WXSDKInstance instance, String ref, Map style, Map paddings, Map margins, @@ -55,34 +54,32 @@ public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, this.mStyle = style; this.mIsCausedByPesudo = byPesudo; - mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (mNode == null) { + component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { return; } if (null != mStyle) { - mNode.getComponentData().getStyles().updateStyle(mStyle, mIsCausedByPesudo); - if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { - if (style.containsKey(Constants.Name.TRANSFORM) && mNode.data.getTransition() == null) { - Map animationMap = new ArrayMap<>(2); - animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); - animationMap - .put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); - mNode.data.addAnimationForElement(animationMap); - } + component.updateStyle(mStyle, mIsCausedByPesudo); + if(style.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null) { + Map animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap + .put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + component.addAnimationForElement(animationMap); } } if (null != paddings) { - mNode.getComponentData().setPaddings(paddings); + component.setPaddings(paddings); } if (null != margins) { - mNode.getComponentData().setMargins(margins); + component.setMargins(margins); } if (null != borders) { mIsBorderSet = true; - mNode.getComponentData().setBorders(borders); + component.setBorders(borders); } } @@ -95,59 +92,50 @@ public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, this.mStyle = style; this.mIsCausedByPesudo = byPesudo; - mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (mNode == null) { + component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { return; } if (null != mStyle) { - mNode.getComponentData().addStyle(mStyle, mIsCausedByPesudo); - if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { - if (style.containsKey(Constants.Name.TRANSFORM) && mNode.data.getTransition() == null) { - Map animationMap = new ArrayMap<>(2); - animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); - animationMap.put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); - mNode.data.addAnimationForElement(animationMap); - WXBridgeManager.getInstance().markDirty(getPageId(), getRef(), true); - } + component.addStyle(mStyle, mIsCausedByPesudo); + if(style.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null){ + Map animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap.put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + component.addAnimationForElement(animationMap); + WXBridgeManager.getInstance().markDirty(component.getInstanceId(), component.getRef(), true); } } if (null != paddings) { - mNode.getComponentData().addShorthand(paddings); + component.addShorthand(paddings); } if (null != margins) { - mNode.getComponentData().addShorthand(margins); + component.addShorthand(margins); } if (null != borders) { mIsBorderSet = true; - mNode.getComponentData().addShorthand(borders); + component.addShorthand(borders); } } @Override - public void executeAction() { // need merge - mNode = WXSDKManager.getInstance().getWXRenderManager().getWXComponentNode(getPageId(), getRef()); - if (mNode == null) { - return; - } - - if (!mNode.getWxInstance().getNeedInterceptRender() && mNode.data != null) { - WXComponent component = mNode.data; - if (mStyle != null) { - if (component.getTransition() != null) { - component.getTransition().updateTranstionParams(mStyle); - if (component.getTransition().hasTransitionProperty(mStyle)) { - component.getTransition().startTransition(mStyle); - } - } else { - component.setTransition(WXTransition.fromMap(mStyle, component)); - component.updateStyles(mStyle); + public void executeAction() { + if (component == null) return; + if (mStyle != null) { + if(component.getTransition() != null){ + component.getTransition().updateTranstionParams(mStyle); + if(component.getTransition().hasTransitionProperty(mStyle)){ + component.getTransition().startTransition(mStyle); } - } else if (mIsBorderSet) { - component.updateStyles(component); + } else { + component.setTransition(WXTransition.fromMap(mStyle, component)); + component.updateStyles(mStyle); } + } else if (mIsBorderSet) { + component.updateStyles(component); } } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java index 2b07955ae1..b5e412e036 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java @@ -51,7 +51,6 @@ public UpdateComponentDataAction(WXSDKInstance instance, String virtualComponent @Override public void executeAction() { - // todo recyclerList这里暂时还不支持预渲染,后续再补上 if(TextUtils.isEmpty(getRef())){ WXLogUtils.e("wrong virtualComponentId split error " + virtualComponentId); return; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java b/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java index a614ba3202..744bfc94e2 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/animation/WXAnimationModule.java @@ -24,7 +24,9 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.annotation.JSMethod; +import com.taobao.weex.bridge.WXBridgeManager; import com.taobao.weex.common.WXModule; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.action.GraphicActionAnimation; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.list.template.TemplateDom; @@ -36,7 +38,7 @@ public void transition(@Nullable String ref, @Nullable String animation, @Nullab if (!TextUtils.isEmpty(ref) && !TextUtils.isEmpty(animation) && mWXSDKInstance != null) { //Due to animation module rely on the result of the css-layout and the batch mechanism of //css-layout, the animation.transition must be delayed the batch time. - GraphicActionAnimation action = new GraphicActionAnimation(mWXSDKInstance, ref, animation, callBack); + BasicGraphicAction action = WXBridgeManager.getInstance().getActionCreator(mWXSDKInstance).createGraphicActionAnimation(mWXSDKInstance, ref, animation, callBack); WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(action.getPageId(), action); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java index 8b8ecae6a7..1c0cbf0b7c 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/node/WXComponentNode.java @@ -36,7 +36,6 @@ import com.taobao.weex.dom.transition.WXTransition; import com.taobao.weex.tracing.Stopwatch; import com.taobao.weex.ui.action.BasicComponentData; -import com.taobao.weex.ui.action.GraphicActionTransformNode; import com.taobao.weex.ui.action.GraphicPosition; import com.taobao.weex.ui.action.GraphicSize; import com.taobao.weex.ui.component.Scrollable; @@ -44,6 +43,7 @@ import com.taobao.weex.ui.component.WXComponentFactory; import com.taobao.weex.ui.component.WXScroller; import com.taobao.weex.ui.component.WXVContainer; +import com.taobao.weex.ui.prerenderaction.PrerenderGraphicActionTransformNode; import com.taobao.weex.utils.WXLogUtils; import java.util.ArrayList; @@ -479,7 +479,7 @@ public WXSDKInstance getWxInstance() { @Override public void run() { - new GraphicActionTransformNode(this, mWxInstance, mComponentData.mRef).executeActionOnRender(); + new PrerenderGraphicActionTransformNode(this, mWxInstance, mComponentData.mRef).executeActionOnRender(); } public void onCreateFinish() { diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/module/WXDomModule.java b/android/sdk/src/main/java/com/taobao/weex/ui/module/WXDomModule.java index 8f8c957380..10966d4e31 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/module/WXDomModule.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/module/WXDomModule.java @@ -21,6 +21,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.bridge.WXBridge; import com.taobao.weex.bridge.WXBridgeManager; import com.taobao.weex.common.WXModule; import com.taobao.weex.dom.binding.JSONUtils; @@ -98,7 +100,7 @@ public Object callDomMethod(String method, JSONArray args, long... parseNanos) { } String ref = args.size() >= 1 ? args.getString(0) : null; JSONObject options = args.size() >= 2 ? args.getJSONObject(1) : null; - new GraphicActionScrollToElement(mWXSDKInstance, ref, options) + WXBridgeManager.getInstance().getActionCreator(mWXSDKInstance).createGraphicActionScrollToElement(mWXSDKInstance, ref, options) .executeActionOnRender(); break; } @@ -123,8 +125,8 @@ public Object callDomMethod(String method, JSONArray args, long... parseNanos) { return null; } // todo:no sure where the request com from - new ActionInvokeMethod(mWXSDKInstance.getInstanceId(), args.getString(0), args.getString(1), args.getJSONArray(2)) - .executeAction(); + WXBridgeManager.getInstance().getActionCreator(mWXSDKInstance).createActionInvokeMethod(mWXSDKInstance.getInstanceId(), + args.getString(0), args.getString(1), args.getJSONArray(2)).executeAction(); break; } case UPDATE_COMPONENT_DATA: @@ -192,8 +194,8 @@ public void invokeMethod(String ref, String method, JSONArray args){ if(ref == null || method == null){ return; } - - new ActionInvokeMethod(mWXSDKInstance.getInstanceId(), ref, method, args) + WXBridgeManager.getInstance().getActionCreator(mWXSDKInstance) + .createActionInvokeMethod(mWXSDKInstance.getInstanceId(), ref, method, args) .executeAction(); } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionCreator.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionCreator.java index 7aaae6bb06..145cfd09aa 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionCreator.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionCreator.java @@ -1,8 +1,125 @@ package com.taobao.weex.ui.prerenderaction; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.IActionCreator; +import com.taobao.weex.ui.action.BasicGraphicAction; +import com.taobao.weex.ui.action.GraphicActionBaseAddElement; +import com.taobao.weex.ui.action.GraphicPosition; +import com.taobao.weex.ui.action.GraphicSize; +import com.taobao.weex.ui.action.IExecutable; + +import java.util.Map; +import java.util.Set; + /** * Description * Created by luciolong on 2019/1/23. */ -public class PrerenderActionCreator { +public class PrerenderActionCreator implements IActionCreator { + @Override + public GraphicActionBaseAddElement createGraphicActionAddElement(@NonNull WXSDKInstance instance, + String ref, + String componentType, + String parentRef, + int index, + Map style, + Map attributes, + Set events, float[] margins, + float[] paddings, + float[] borders) { + return new PrerenderGraphicActionAddElement(instance, + ref, componentType, parentRef, + index, style, attributes, events, + margins, paddings, borders); + } + + @Override + public BasicGraphicAction createGraphicActionLayout(WXSDKInstance instance, + String ref, + GraphicPosition layoutPosition, + GraphicSize layoutSize, + boolean isRTL) { + return new PrerenderGraphicActionLayout(instance, ref, layoutPosition, layoutSize, isRTL); + } + + @Override + public IExecutable createActionInvokeMethod(String pageId, String ref, String method, JSONArray args) { + return new PrerenderActionInvokeMethod(pageId, ref, method, args); + } + + @Override + public BasicGraphicAction createGraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { + return new PrerenderGraphicActionAddEvent(instance, ref,event); + } + + @Override + public BasicGraphicAction createGraphicActionAnimation(@NonNull WXSDKInstance instance, + @NonNull String ref, + @Nullable String animation, + @Nullable String callBack) { + return new PrerenderGraphicActionAnimation(instance, ref, animation, callBack); + } + + @Override + public BasicGraphicAction createGraphicActionCreateBody(@NonNull WXSDKInstance instance, + String ref, + String componentType, + Map style, + Map attributes, + Set events, + float[] margins, + float[] paddings, + float[] borders) { + return new PrerenderGraphicActionCreateBody(instance, ref, componentType, style, attributes, events, margins, paddings, borders); + } + + @Override + public BasicGraphicAction createGraphicActionCreateFinish(@NonNull WXSDKInstance instance) { + return new PrerenderGraphicActionCreateFinish(instance); + } + + @Override + public BasicGraphicAction createGraphicActionMoveElement(WXSDKInstance instance, String ref, String parentRef, int index) { + return new PrerenderGraphicActionMoveElement(instance, ref, parentRef, index); + } + + @Override + public BasicGraphicAction createGraphicActionRemoveElement(WXSDKInstance instance, String ref) { + return new PrerenderGraphicActionRemoveElement(instance, ref); + } + + @Override + public BasicGraphicAction createGraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event) { + return new PrerenderGraphicActionRemoveEvent(instance, ref, event); + } + + @Override + public BasicGraphicAction createGraphicActionRenderSuccess(@NonNull WXSDKInstance instance) { + return new PrerenderGraphicActionRenderSuccess(instance); + } + + @Override + public BasicGraphicAction createGraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObject options) { + return new PrerenderGraphicActionScrollToElement(instance, ref, options); + } + + @Override + public BasicGraphicAction createGraphicActionUpdateAttr(WXSDKInstance instance, String ref, Map attrs) { + return new PrerenderGraphicActionUpdateAttr(instance, ref, attrs); + } + + @Override + public BasicGraphicAction createGraphicActionUpdateStyle(WXSDKInstance instance, + String ref, + Map style, + Map paddings, + Map margins, + Map borders) { + return new PrerenderGraphicActionUpdateStyle(instance, ref, style, paddings, margins, borders); + } } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionInvokeMethod.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionInvokeMethod.java index 9dff389fa9..9aa80bd6d6 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionInvokeMethod.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderActionInvokeMethod.java @@ -16,27 +16,26 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import com.alibaba.fastjson.JSONArray; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.action.IExecutable; import com.taobao.weex.ui.component.node.WXComponentNode; -import com.taobao.weex.utils.WXLogUtils; /** * Created by listen on 18/01/10. */ -public class ActionInvokeMethod implements IExecutable { +public class PrerenderActionInvokeMethod implements IExecutable { - private static final String TAG = "ActionInvokeMethod"; + private static final String TAG = "PrerenderActionInvokeMethod"; private final String mMethod; private final JSONArray mArgs; private String mPageId; private String mRef; - public ActionInvokeMethod(String pageId, String ref, String method, JSONArray args) { + PrerenderActionInvokeMethod(String pageId, String ref, String method, JSONArray args) { this.mPageId = pageId; this.mRef = ref; this.mMethod = method; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAbstractAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAbstractAddElement.java index 44c0f91c02..0091530c43 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAbstractAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAbstractAddElement.java @@ -16,18 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.dom.CSSShorthand; +import com.taobao.weex.ui.action.BasicComponentData; +import com.taobao.weex.ui.action.GraphicActionBaseAddElement; import com.taobao.weex.ui.component.node.WXComponentNodeBuilder; import java.util.Map; import java.util.Set; -public abstract class GraphicActionAbstractAddElement extends BasicGraphicAction { +public abstract class PrerenderGraphicActionAbstractAddElement extends GraphicActionBaseAddElement { protected String mComponentType; protected String mParentRef; @@ -40,7 +42,7 @@ public abstract class GraphicActionAbstractAddElement extends BasicGraphicAction protected float[] mBorders; private long startTime; - public GraphicActionAbstractAddElement(WXSDKInstance instance, String ref) { + public PrerenderGraphicActionAbstractAddElement(WXSDKInstance instance, String ref) { super(instance, ref); startTime = System.currentTimeMillis(); } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddElement.java index 9a3fac8754..4842ac6fdc 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddElement.java @@ -16,21 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import android.support.annotation.NonNull; import android.support.annotation.RestrictTo; import android.support.annotation.RestrictTo.Scope; import android.support.annotation.WorkerThread; - import android.support.v4.util.ArrayMap; import android.util.Log; + import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.common.WXErrorCode; -import com.taobao.weex.ui.component.node.WXComponentNode; import com.taobao.weex.performance.WXAnalyzerDataTransfer; +import com.taobao.weex.ui.action.BasicComponentData; +import com.taobao.weex.ui.action.GraphicPosition; +import com.taobao.weex.ui.action.GraphicSize; import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.node.WXComponentNode; import com.taobao.weex.utils.WXExceptionUtils; import java.util.Arrays; @@ -38,22 +41,22 @@ import java.util.Map; import java.util.Set; -public class GraphicActionAddElement extends GraphicActionAbstractAddElement { +public class PrerenderGraphicActionAddElement extends PrerenderGraphicActionAbstractAddElement { private GraphicPosition layoutPosition; private GraphicSize layoutSize; private boolean isLayoutRTL; private WXComponentNode childNode; - public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, - String componentType, String parentRef, - int index, - Map style, - Map attributes, - Set events, - float[] margins, - float[] paddings, - float[] borders) { + PrerenderGraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, + String componentType, String parentRef, + int index, + Map style, + Map attributes, + Set events, + float[] margins, + float[] paddings, + float[] borders) { super(instance, ref); this.mComponentType = componentType; this.mParentRef = parentRef; @@ -127,7 +130,7 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), WXErrorCode.WX_RENDER_ERR_CONTAINER_TYPE, - "GraphicActionAddElement", + "PrerenderGraphicActionAddElement", String.format(Locale.ENGLISH, "You are trying to add a %s to a %2$s, which is illegal as %2$s is not a container", componentType, WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef).getComponentType()), @@ -139,6 +142,7 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref, @RestrictTo(Scope.LIBRARY) @WorkerThread + @Override public void setRTL(boolean isRTL){ isLayoutRTL = isRTL; childNode.setIsLayoutRTL(isRTL); @@ -146,6 +150,7 @@ public void setRTL(boolean isRTL){ @RestrictTo(Scope.LIBRARY) @WorkerThread + @Override public void setSize(GraphicSize graphicSize){ this.layoutSize = graphicSize; childNode.setLayoutSize(graphicSize); @@ -153,6 +158,7 @@ public void setSize(GraphicSize graphicSize){ @RestrictTo(Scope.LIBRARY) @WorkerThread + @Override public void setPosition(GraphicPosition position){ this.layoutPosition = position; childNode.setLayoutPosition(position); @@ -160,6 +166,7 @@ public void setPosition(GraphicPosition position){ @RestrictTo(Scope.LIBRARY) @WorkerThread + @Override public void setIndex(int index){ childNode.setIndex(index); } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddEvent.java index c555ffd587..04d8bdf893 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAddEvent.java @@ -21,16 +21,17 @@ import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.dom.WXEvent; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.node.WXComponentNode; /** * Created by listen on 18/01/11. */ -public class GraphicActionAddEvent extends BasicGraphicAction { +public class PrerenderGraphicActionAddEvent extends BasicGraphicAction { private final String mEvent; - public GraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { + PrerenderGraphicActionAddEvent(WXSDKInstance instance, String ref, Object event) { super(instance, ref); this.mEvent = WXEvent.getEventName(event); } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAnimation.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAnimation.java index 4ac3add3ed..bb965c441e 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAnimation.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionAnimation.java @@ -16,274 +16,32 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.ArgbEvaluator; -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import android.graphics.drawable.ColorDrawable; -import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.view.animation.PathInterpolatorCompat; -import android.text.TextUtils; -import android.util.Pair; -import android.view.View; -import android.view.ViewGroup; -import android.view.animation.AccelerateDecelerateInterpolator; -import android.view.animation.AccelerateInterpolator; -import android.view.animation.DecelerateInterpolator; -import android.view.animation.Interpolator; -import android.view.animation.LinearInterpolator; -import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.common.Constants; -import com.taobao.weex.ui.animation.BackgroundColorProperty; -import com.taobao.weex.ui.animation.HeightProperty; -import com.taobao.weex.ui.animation.WXAnimationBean; -import com.taobao.weex.ui.animation.WXAnimationModule; -import com.taobao.weex.ui.animation.WidthProperty; -import com.taobao.weex.ui.component.WXComponent; -import com.taobao.weex.ui.component.list.template.TemplateDom; -import com.taobao.weex.ui.view.border.BorderDrawable; -import com.taobao.weex.utils.SingleFunctionParser; -import com.taobao.weex.utils.WXLogUtils; -import com.taobao.weex.utils.WXResourceUtils; -import com.taobao.weex.utils.WXUtils; -import com.taobao.weex.utils.WXViewUtils; +import com.taobao.weex.ui.action.GraphicActionAnimation; -import java.util.HashMap; -import java.util.List; +public class PrerenderGraphicActionAnimation extends GraphicActionAnimation { -public class GraphicActionAnimation extends BasicGraphicAction { - private final static String TAG = "GraphicActionAnimation"; + PrerenderGraphicActionAnimation(@NonNull WXSDKInstance instance, @NonNull String ref, @Nullable String animation, + @Nullable final String callBack) { + super(instance, ref, animation, callBack); - private final boolean styleNeedInit; - - @Nullable - private - final String callback; - - @Nullable - private - WXAnimationBean mAnimationBean; - - public GraphicActionAnimation(@NonNull WXSDKInstance instance, @NonNull String ref, @NonNull WXAnimationBean animationBean) { - super(instance, ref); - this.styleNeedInit = false; - this.callback = null; - this.mAnimationBean = animationBean; - } - - public GraphicActionAnimation(@NonNull WXSDKInstance instance, @NonNull String ref, @Nullable String animation, - @Nullable final String callBack) { - super(instance, ref); - this.styleNeedInit = true; - this.callback = callBack; - if (!TextUtils.isEmpty(animation)) { - this.mAnimationBean = JSONObject.parseObject(animation, WXAnimationBean.class); - } - } - public GraphicActionAnimation(@NonNull WXSDKInstance instance, @NonNull String ref, @NonNull WXAnimationBean animationBean, - @Nullable final String callBack) { - super(instance, ref); - this.styleNeedInit = false; - this.mAnimationBean = animationBean; - this.callback = callBack; } @Override public void executeAction() { - if (null == mAnimationBean) { - return; - } - - WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); - if (component == null) { - if(!TemplateDom.isVirtualDomRef(getRef())){ - return; - } - component = TemplateDom.findVirtualComponentByVRef(getPageId(), getRef()); - if(component == null){ - return; - } - } WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); if (instance == null || instance.getNeedInterceptRender()) { return; } - if (null != mAnimationBean.styles) { - if(styleNeedInit) { - // Synchronize transformOrigin between component styles and animation style before - // animation start. - String transformOrigin = (String) component.getStyles().get(Constants.Name.TRANSFORM_ORIGIN); - if (TextUtils.isEmpty(mAnimationBean.styles.transformOrigin)) { - mAnimationBean.styles.transformOrigin = transformOrigin; - } - mAnimationBean.styles.init(mAnimationBean.styles.transformOrigin, - mAnimationBean.styles.transform, (int) component.getLayoutWidth(), - (int) component.getLayoutHeight(), - instance.getInstanceViewPortWidth(), instance); - } - startAnimation(instance, component); - } - } - - - - private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) { - if (component != null) { - if (mAnimationBean != null) { - component.setNeedLayoutOnAnimation(mAnimationBean.needLayout); - } - if (component.getHostView() == null) { - WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean, callback); - component.postAnimation(holder); - } else { - try { - Animator animator = createAnimator(component.getHostView(), instance - .getInstanceViewPortWidth()); - if (animator != null) { - Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && component - .isLayerTypeEnabled() ) { - component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null); - } - Interpolator interpolator = createTimeInterpolator(); - if (animatorCallback != null) { - animator.addListener(animatorCallback); - } - if (interpolator != null) { - animator.setInterpolator(interpolator); - } - component.getHostView().setCameraDistance(mAnimationBean.styles.getCameraDistance()); - animator.setDuration(mAnimationBean.duration); - animator.start(); - } - } catch (RuntimeException e) { - WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e)); - } - } - } - } - - private - @Nullable - ObjectAnimator createAnimator(final View target, final int viewPortWidth) { - if (target == null) { - return null; - } - WXAnimationBean.Style style = mAnimationBean.styles; - if (style != null) { - ObjectAnimator animator; - List holders = style.getHolders(); - if (!TextUtils.isEmpty(style.backgroundColor)) { - BorderDrawable borderDrawable; - if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) { - holders.add(PropertyValuesHolder.ofObject( - new BackgroundColorProperty(), new ArgbEvaluator(), - borderDrawable.getColor(), - WXResourceUtils.getColor(style.backgroundColor))); - } else if (target.getBackground() instanceof ColorDrawable) { - holders.add(PropertyValuesHolder.ofObject( - new BackgroundColorProperty(), new ArgbEvaluator(), - ((ColorDrawable) target.getBackground()).getColor(), - WXResourceUtils.getColor(style.backgroundColor))); - } - } - - if (target.getLayoutParams() != null && - (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) { - ViewGroup.LayoutParams layoutParams = target.getLayoutParams(); - if (!TextUtils.isEmpty(style.width)) { - holders.add(PropertyValuesHolder.ofInt(new WidthProperty(), layoutParams.width, - (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth))); - } - if (!TextUtils.isEmpty(style.height)) { - holders.add(PropertyValuesHolder.ofInt(new HeightProperty(), layoutParams.height, - (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth))); - } - } - - if (style.getPivot() != null) { - Pair pair = style.getPivot(); - target.setPivotX(pair.first); - target.setPivotY(pair.second); - } - animator = ObjectAnimator.ofPropertyValuesHolder( - target, holders.toArray(new PropertyValuesHolder[holders.size()])); - animator.setStartDelay(mAnimationBean.delay); - return animator; - } else { - return null; - } - } - - private - @Nullable - Animator.AnimatorListener createAnimatorListener(final WXSDKInstance instance, @Nullable final String callBack) { - if (!TextUtils.isEmpty(callBack)) { - return new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - if (instance == null || instance.isDestroy()) { - WXLogUtils.e("RenderContextImpl-onAnimationEnd WXSDKInstance == null NPE or instance is destroyed"); - } else { - WXSDKManager.getInstance().callback(instance.getInstanceId(), - callBack, - new HashMap()); - } - } - }; - } else { - return null; - } - } - - private - @Nullable - Interpolator createTimeInterpolator() { - String interpolator = mAnimationBean.timingFunction; - if (!TextUtils.isEmpty(interpolator)) { - switch (interpolator) { - case WXAnimationBean.EASE_IN: - return new AccelerateInterpolator(); - case WXAnimationBean.EASE_OUT: - return new DecelerateInterpolator(); - case WXAnimationBean.EASE_IN_OUT: - return new AccelerateDecelerateInterpolator(); - case WXAnimationBean.LINEAR: - return new LinearInterpolator(); - default: - //Parse cubic-bezier - try { - SingleFunctionParser parser = new SingleFunctionParser<>( - mAnimationBean.timingFunction, - new SingleFunctionParser.FlatMapper() { - @Override - public Float map(String raw) { - return Float.parseFloat(raw); - } - }); - List params = parser.parse(WXAnimationBean.CUBIC_BEZIER); - if (params != null && params.size() == WXAnimationBean.NUM_CUBIC_PARAM) { - return PathInterpolatorCompat.create( - params.get(0), params.get(1), params.get(2), params.get(3)); - } else { - return null; - } - } catch (RuntimeException e) { - return null; - } - } - } - return null; + super.executeAction(); } } \ No newline at end of file diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateBody.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateBody.java index ca7076ff5b..40dd837aaf 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateBody.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateBody.java @@ -16,28 +16,29 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.action.BasicComponentData; import com.taobao.weex.ui.component.node.WXComponentNode; import java.util.Map; import java.util.Set; -public class GraphicActionCreateBody extends GraphicActionAbstractAddElement { +public class PrerenderGraphicActionCreateBody extends PrerenderGraphicActionAbstractAddElement { private WXComponentNode node; - public GraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, - String componentType, - Map style, - Map attributes, - Set events, - float[] margins, - float[] paddings, - float[] borders) { + PrerenderGraphicActionCreateBody(@NonNull WXSDKInstance instance, String ref, + String componentType, + Map style, + Map attributes, + Set events, + float[] margins, + float[] paddings, + float[] borders) { super(instance, ref); this.mComponentType = componentType; this.mStyle = style; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateFinish.java index 039643c0fe..084cb2592c 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateFinish.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionCreateFinish.java @@ -16,19 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.performance.WXInstanceApm; +import com.taobao.weex.ui.action.BasicGraphicAction; /** * Created by listen on 18/01/09. */ -public class GraphicActionCreateFinish extends BasicGraphicAction { +public class PrerenderGraphicActionCreateFinish extends BasicGraphicAction { - public GraphicActionCreateFinish(@NonNull WXSDKInstance instance) { + PrerenderGraphicActionCreateFinish(@NonNull WXSDKInstance instance) { super(instance, ""); instance.getApmForInstance().onStage(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH); instance.getApmForInstance().extInfo.put(WXInstanceApm.KEY_PAGE_STAGES_CREATE_FINISH,true); diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionLayout.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionLayout.java index 9a6bad3826..2d97c58142 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionLayout.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionLayout.java @@ -16,21 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; -import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.action.BasicGraphicAction; +import com.taobao.weex.ui.action.GraphicPosition; +import com.taobao.weex.ui.action.GraphicSize; import com.taobao.weex.ui.component.node.WXComponentNode; import com.taobao.weex.utils.WXLogUtils; -public class GraphicActionLayout extends BasicGraphicAction { +public class PrerenderGraphicActionLayout extends BasicGraphicAction { private final GraphicPosition mLayoutPosition; private final GraphicSize mLayoutSize; private final boolean mIsLayoutRTL; - public GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition layoutPosition, GraphicSize layoutSize, boolean isRTL) { + PrerenderGraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition layoutPosition, GraphicSize layoutSize, boolean isRTL) { super(instance, ref); this.mLayoutPosition = layoutPosition; this.mLayoutSize = layoutSize; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionMoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionMoveElement.java index 4f18265ccc..7af99d23d6 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionMoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionMoveElement.java @@ -16,19 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import com.taobao.weex.WXSDKInstance; - import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.node.WXComponentNode; -public class GraphicActionMoveElement extends BasicGraphicAction { +public class PrerenderGraphicActionMoveElement extends BasicGraphicAction { private String mParentref; private int mIndex; - public GraphicActionMoveElement(WXSDKInstance instance, String ref, String parentRef, int index) { + PrerenderGraphicActionMoveElement(WXSDKInstance instance, String ref, String parentRef, int index) { super(instance, ref); this.mParentref = parentRef; this.mIndex = index; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveElement.java index 01191d96d9..d08510cef7 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveElement.java @@ -16,15 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.node.WXComponentNode; -public class GraphicActionRemoveElement extends BasicGraphicAction { +public class PrerenderGraphicActionRemoveElement extends BasicGraphicAction { - public GraphicActionRemoveElement(WXSDKInstance instance, String ref) { + PrerenderGraphicActionRemoveElement(WXSDKInstance instance, String ref) { super(instance, ref); } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveEvent.java index e52d3e832a..828ef6b160 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRemoveEvent.java @@ -16,21 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; import com.taobao.weex.dom.WXEvent; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.node.WXComponentNode; /** * Created by listen on 18/01/11. */ -public class GraphicActionRemoveEvent extends BasicGraphicAction { +public class PrerenderGraphicActionRemoveEvent extends BasicGraphicAction { private final String mEvent; - public GraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event) { + PrerenderGraphicActionRemoveEvent(WXSDKInstance instance, String ref, Object event) { super(instance, ref); this.mEvent = WXEvent.getEventName(event); } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRenderSuccess.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRenderSuccess.java index 7ec9ebdf0c..9c361f0a2c 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRenderSuccess.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionRenderSuccess.java @@ -16,16 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.node.WXComponentNode; -public class GraphicActionRenderSuccess extends BasicGraphicAction { +public class PrerenderGraphicActionRenderSuccess extends BasicGraphicAction { - public GraphicActionRenderSuccess(@NonNull WXSDKInstance instance) { + PrerenderGraphicActionRenderSuccess(@NonNull WXSDKInstance instance) { super(instance, ""); } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionScrollToElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionScrollToElement.java index c9f0a36d4d..8365f4d869 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionScrollToElement.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionScrollToElement.java @@ -16,21 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.node.WXComponentNode; /** * Created by listen on 18/01/09. */ -public class GraphicActionScrollToElement extends BasicGraphicAction { +public class PrerenderGraphicActionScrollToElement extends BasicGraphicAction { private final JSONObject mOptions; - public GraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObject options) { + PrerenderGraphicActionScrollToElement(WXSDKInstance instance, String ref, JSONObject options) { super(instance, ref); this.mOptions = options; } diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionTransformNode.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionTransformNode.java index f7c146600b..32375ee1d7 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionTransformNode.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionTransformNode.java @@ -16,22 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import android.support.annotation.NonNull; import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.node.WXComponentNode; /** * Description * Created by luciolong on 02/08/2018. */ -public class GraphicActionTransformNode extends BasicGraphicAction { +public class PrerenderGraphicActionTransformNode extends BasicGraphicAction { @NonNull private final WXComponentNode mNode; - public GraphicActionTransformNode(@NonNull WXComponentNode node, WXSDKInstance instance, String ref) { + public PrerenderGraphicActionTransformNode(@NonNull WXComponentNode node, WXSDKInstance instance, String ref) { super(instance, ref); this.mNode = node; this.mNode.createComponent(); diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateAttr.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateAttr.java index 828d5f9662..7381ade410 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateAttr.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateAttr.java @@ -16,21 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.node.WXComponentNode; import java.util.Map; -public class GraphicActionUpdateAttr extends BasicGraphicAction { +public class PrerenderGraphicActionUpdateAttr extends BasicGraphicAction { private Map mAttrs; private WXComponentNode mNode; - public GraphicActionUpdateAttr(WXSDKInstance instance, String ref, - Map attrs) { + PrerenderGraphicActionUpdateAttr(WXSDKInstance instance, String ref, + Map attrs) { super(instance, ref); this.mAttrs = attrs; diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateStyle.java b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateStyle.java index 0bd05e3d28..089b6097e6 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateStyle.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/prerenderaction/PrerenderGraphicActionUpdateStyle.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package com.taobao.weex.ui.action; +package com.taobao.weex.ui.prerenderaction; import android.support.v4.util.ArrayMap; @@ -26,31 +26,32 @@ import com.taobao.weex.common.Constants; import com.taobao.weex.dom.CSSShorthand; import com.taobao.weex.dom.transition.WXTransition; +import com.taobao.weex.ui.action.BasicGraphicAction; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.node.WXComponentNode; import java.util.Map; -public class GraphicActionUpdateStyle extends BasicGraphicAction { +public class PrerenderGraphicActionUpdateStyle extends BasicGraphicAction { private Map mStyle; private WXComponentNode mNode; private boolean mIsCausedByPesudo; private boolean mIsBorderSet; - public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, - Map style, - Map paddings, - Map margins, - Map borders) { + PrerenderGraphicActionUpdateStyle(WXSDKInstance instance, String ref, + Map style, + Map paddings, + Map margins, + Map borders) { this(instance, ref, style, paddings, margins, borders, false); } - public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, - Map style, - CSSShorthand paddings, - CSSShorthand margins, - CSSShorthand borders, boolean byPesudo) { + public PrerenderGraphicActionUpdateStyle(WXSDKInstance instance, String ref, + Map style, + CSSShorthand paddings, + CSSShorthand margins, + CSSShorthand borders, boolean byPesudo) { super(instance, ref); this.mStyle = style; this.mIsCausedByPesudo = byPesudo; @@ -86,11 +87,11 @@ public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, } } - public GraphicActionUpdateStyle(WXSDKInstance instance, String ref, - Map style, - Map paddings, - Map margins, - Map borders, boolean byPesudo) { + public PrerenderGraphicActionUpdateStyle(WXSDKInstance instance, String ref, + Map style, + Map paddings, + Map margins, + Map borders, boolean byPesudo) { super(instance, ref); this.mStyle = style; this.mIsCausedByPesudo = byPesudo;