[WEEX-355][android] recycle-list adapter for weex-core new architecture
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b049f80e Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b049f80e Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b049f80e Branch: refs/heads/master Commit: b049f80ee63c9a2a2b13fde6144ee6e462693f1b Parents: 0d2681f Author: jianbai.gbj <[email protected]> Authored: Mon May 7 20:54:22 2018 +0800 Committer: YorkShen <[email protected]> Committed: Mon May 14 12:15:29 2018 +0800 ---------------------------------------------------------------------- .../java/com/taobao/weex/bridge/WXBridge.java | 10 +- .../com/taobao/weex/bridge/WXBridgeManager.java | 13 +- .../java/com/taobao/weex/common/Constants.java | 2 + .../java/com/taobao/weex/common/IWXBridge.java | 4 +- .../main/java/com/taobao/weex/dom/WXAttr.java | 50 +++- .../main/java/com/taobao/weex/dom/WXEvent.java | 47 +++- .../main/java/com/taobao/weex/dom/WXStyle.java | 77 ++++-- .../com/taobao/weex/dom/binding/ELUtils.java | 13 +- .../com/taobao/weex/dom/binding/JSONUtils.java | 51 ++++ .../weex/ui/action/BasicComponentData.java | 43 ++++ .../weex/ui/action/GraphicActionAddElement.java | 2 +- .../weex/ui/action/GraphicActionLayout.java | 2 +- .../ui/action/GraphicActionUpdateStyle.java | 2 +- .../taobao/weex/ui/action/GraphicPosition.java | 8 + .../com/taobao/weex/ui/action/GraphicSize.java | 5 + .../ui/action/UpdateComponentDataAction.java | 69 ++++++ .../weex/ui/component/ComponentUtils.java | 121 --------- .../taobao/weex/ui/component/WXComponent.java | 91 ++++++- .../ui/component/basic/WXBasicComponent.java | 12 +- .../ui/component/binding/AsynLayoutTask.java | 60 +++++ .../weex/ui/component/binding/Layouts.java | 146 +++-------- .../weex/ui/component/binding/Statements.java | 98 ++++++-- .../ui/component/list/BasicListComponent.java | 30 ++- .../taobao/weex/ui/component/list/WXCell.java | 35 ++- .../weex/ui/component/list/WXListComponent.java | 6 +- .../list/template/AsyncCellLoadTask.java | 1 + .../ui/component/list/template/PositionRef.java | 10 +- .../list/template/TemplateViewHolder.java | 27 +- .../list/template/WXRecyclerTemplateList.java | 247 +++++++++++++------ .../template/jni/NativeRenderObjectUtils.java | 78 ++++++ .../com/taobao/weex/ui/module/WXDomModule.java | 10 + weex_core/Source/CMakeLists.txt | 1 + .../android/bridge/impl/bridge_impl_android.cpp | 7 +- .../android/bridge/impl/bridge_impl_android.h | 3 +- .../native_render_object_utils_impl_android.cpp | 209 ++++++++++++++++ .../native_render_object_utils_impl_android.h | 34 +++ .../bridge/impl/weexcore_impl_android.cpp | 9 + weex_core/Source/android/jniprebuild/jni_files | 1 + .../Source/android/jniprebuild/jni_load.cc | 2 + .../jniheader/ContentBoxMeasurement_jni.h | 2 +- .../jniheader/NativeRenderObjectUtils_jni.h | 200 +++++++++++++++ .../jniprebuild/jniheader/WXBridge_jni.h | 12 +- .../Source/android/jniprebuild/prebuild.sh | 2 +- weex_core/Source/core/bridge/bridge.h | 3 +- weex_core/Source/core/layout/layout.h | 16 ++ weex_core/Source/core/parser/dom_parser.cpp | 151 +++++------- weex_core/Source/core/parser/dom_parser.h | 4 + .../render/action/render_action_add_element.cpp | 5 +- .../render/action/render_action_add_element.h | 3 +- .../core/render/node/factory/i_render_object.h | 7 + .../core/render/node/factory/render_creator.cpp | 6 +- .../core/render/node/factory/render_type.h | 2 + weex_core/Source/core/render/node/render_list.h | 94 +++++-- .../Source/core/render/node/render_object.h | 45 +++- weex_core/Source/core/render/node/render_text.h | 3 - .../Source/core/render/page/render_page.cpp | 25 +- weex_core/Source/core/render/page/render_page.h | 2 +- weex_core/debug.sh | 2 + 58 files changed, 1655 insertions(+), 565 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java index 667d8e0..37e4493 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java @@ -65,6 +65,7 @@ public class WXBridge implements IWXBridge { private native void nativeTakeHeapSnapshot(String filename); private native void nativeBindMeasurementToWXCore(String instanceId, String ref, ContentBoxMeasurement contentBoxMeasurement); + private native void nativeBindMeasurementToRenderObject(long ptr, ContentBoxMeasurement contentBoxMeasurement); private native void nativeSetRenderContainerWrapContent(boolean wrap, String instanceId); @@ -327,12 +328,12 @@ public class WXBridge implements IWXBridge { @Override public int callAddElement(String instanceId, String componentType, String ref, int index, String parentRef, HashMap<String, String> styles, HashMap<String, String> attributes, HashSet<String> events, - float[] margins, float[] paddings, float[] borders) { + float[] margins, float[] paddings, float[] borders, boolean willLayout) { int errorCode = IWXBridge.INSTANCE_RENDERING; try { errorCode = WXBridgeManager.getInstance().callAddElement(instanceId, componentType, ref, index, parentRef, - styles, attributes, events, margins, paddings, borders); + styles, attributes, events, margins, paddings, borders, willLayout); } catch (Throwable e) { //catch everything during call native. if (WXEnvironment.isApkDebugable()) { @@ -516,6 +517,11 @@ public class WXBridge implements IWXBridge { } @Override + public void bindMeasurementToRenderObject(long ptr, ContentBoxMeasurement contentBoxMeasurement){ + nativeBindMeasurementToRenderObject(ptr, contentBoxMeasurement); + } + + @Override public void setRenderContainerWrapContent(boolean wrap, String instanceId) { nativeSetRenderContainerWrapContent(wrap, instanceId); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java ---------------------------------------------------------------------- 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 ea27602..560358d 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 @@ -2285,7 +2285,7 @@ public class WXBridgeManager implements Callback, BactchExecutor { public int callAddElement(String pageId, String componentType, String ref, int index, String parentRef, HashMap<String, String> styles, HashMap<String, String> attributes, HashSet<String> events, - float[] margins, float[] paddings, float[] borders) { + float[] margins, float[] paddings, float[] borders,boolean willLayout) { long start = System.currentTimeMillis(); if (TextUtils.isEmpty(pageId) || TextUtils.isEmpty(componentType) || TextUtils.isEmpty(ref)) { WXLogUtils.d("[WXBridgeManager] callAddElement: call CreateBody tasks is null"); @@ -2315,7 +2315,11 @@ public class WXBridgeManager implements Callback, BactchExecutor { if (WXSDKManager.getInstance().getSDKInstance(pageId) != null) { final GraphicActionAddElement action = new GraphicActionAddElement(pageId, ref, componentType, parentRef, index, styles, attributes, events, margins, paddings, borders); - WXSDKManager.getInstance().getSDKInstance(pageId).addInActiveAddElementAction(ref, action); + if(willLayout) { + WXSDKManager.getInstance().getSDKInstance(pageId).addInActiveAddElementAction(ref, action); + }else{ + WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(pageId, action); + } } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callAddElement exception: ", e); @@ -2627,6 +2631,11 @@ public class WXBridgeManager implements Callback, BactchExecutor { mWXBridge.bindMeasurementToWXCore(instanceId, ref, contentBoxMeasurement); } + public void bindMeasurementToRenderObject(long ptr, ContentBoxMeasurement contentBoxMeasurement){ + mWXBridge.bindMeasurementToRenderObject(ptr, contentBoxMeasurement); + } + + /** * Native: Layout * @param instanceId http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/common/Constants.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/common/Constants.java b/android/sdk/src/main/java/com/taobao/weex/common/Constants.java index d5e4ee1..7731bd3 100644 --- a/android/sdk/src/main/java/com/taobao/weex/common/Constants.java +++ b/android/sdk/src/main/java/com/taobao/weex/common/Constants.java @@ -233,6 +233,8 @@ public class Constants { String NEST_SCROLLING_ENABLED = "nestedScrollingEnabled"; + + String ORIENTATION = "orientation"; } public interface Value { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java b/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java index 5213854..35f6bf1 100644 --- a/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java +++ b/android/sdk/src/main/java/com/taobao/weex/common/IWXBridge.java @@ -126,7 +126,7 @@ public interface IWXBridge extends IWXObject { public int callAddElement(String instanceId, String componentType, String ref, int index, String parentRef, HashMap<String, String> styles, HashMap<String, String> attributes, HashSet<String> events, - float[] margins, float[] paddings, float[] borders); + float[] margins, float[] paddings, float[] borders, boolean willLayout); int callRemoveElement(String instanceId, String ref); @@ -155,6 +155,8 @@ public interface IWXBridge extends IWXObject { void bindMeasurementToWXCore(String instanceId, String ref, ContentBoxMeasurement contentBoxMeasurement); + void bindMeasurementToRenderObject(long ptr, ContentBoxMeasurement contentBoxMeasurement); + void setRenderContainerWrapContent(boolean wrap, String instanceId); int printFirstScreenRenderTime(String instanceId); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java index ab009bd..80a330b 100644 --- a/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java +++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java @@ -52,7 +52,7 @@ public class WXAttr implements Map<String, Object>,Cloneable { /** * static attrs * */ - private @NonNull final Map<String, Object> attr; + private @NonNull Map<String, Object> attr; /** * dynamic binding attrs, can be null, only weex use @@ -70,11 +70,12 @@ public class WXAttr implements Map<String, Object>,Cloneable { public WXAttr(@NonNull Map<String,Object> standardMap) { this(); - attr.putAll(filterBindingStatement(standardMap)); + attr.putAll(standardMap); } public WXAttr(@NonNull Map<String,Object> standardMap, int extra){ - attr = standardMap; + this(); + attr.putAll(standardMap); } public static String getPrefix(Map<String, Object> attr) { @@ -254,6 +255,20 @@ public class WXAttr implements Map<String, Object>,Cloneable { return scrollDirection.toString(); } + public int getOrientation() { + String direction = getScrollDirection(); + if(!TextUtils.isEmpty(direction)){ + if(direction.equals(Constants.Value.HORIZONTAL.equals(direction))){ + return Constants.Orientation.HORIZONTAL; + } + } + Object value = get(Name.ORIENTATION); + if(value != null && Constants.Value.HORIZONTAL.equals(value.toString())){ + return Constants.Orientation.HORIZONTAL; + } + return Constants.Orientation.VERTICAL; + } + public float getElevation(int viewPortW) { Object obj = get(Constants.Name.ELEVATION); float ret = Float.NaN; @@ -402,7 +417,7 @@ public class WXAttr implements Map<String, Object>,Cloneable { @Override public Object put(String key, Object value) { - if(filterBindingStatement(key, value)){ + if(addBindingAttrIfStatement(key, value)){ return null; } return attr.put(key,value); @@ -410,7 +425,7 @@ public class WXAttr implements Map<String, Object>,Cloneable { @Override public void putAll(Map<? extends String, ?> map) { - this.attr.putAll(filterBindingStatement(map)); + this.attr.putAll(map); } @Override @@ -453,10 +468,18 @@ public class WXAttr implements Map<String, Object>,Cloneable { } + + public void parseStatements(){ + if(this.attr != null){ + this.attr = filterStatementsFromAttrs(this.attr); + } + } + + /** * filter dynamic state ment * */ - public Map<String, Object> filterBindingStatement(Map attrs) { + private Map<String, Object> filterStatementsFromAttrs(Map attrs) { if(attrs == null || attrs.size() == 0){ return attrs; } @@ -464,7 +487,12 @@ public class WXAttr implements Map<String, Object>,Cloneable { Iterator<Entry<String,Object>> it = entries.iterator(); while (it.hasNext()){ Map.Entry<String,Object> entry = it.next(); - if(filterBindingStatement(entry.getKey(), entry.getValue())){ + if(COMPONENT_PROPS.equals(entry.getKey())){ + Object blockValue = ELUtils.bindingBlock(entry.getValue()); + entry.setValue(blockValue); + continue; + } + if(addBindingAttrIfStatement(entry.getKey(), entry.getValue())){ it.remove(); } } @@ -474,11 +502,7 @@ public class WXAttr implements Map<String, Object>,Cloneable { /** * filter dynamic attrs and statements * */ - private boolean filterBindingStatement(String key, Object value) { - if(COMPONENT_PROPS.equals(key)){ - ELUtils.bindingBlock(value); - return false; - } + private boolean addBindingAttrIfStatement(String key, Object value) { for(String exclude : EXCLUDES_BINDING){ if(key.equals(exclude)){ return false; @@ -527,7 +551,7 @@ public class WXAttr implements Map<String, Object>,Cloneable { } @Override - protected WXAttr clone() { + public WXAttr clone() { WXAttr wxAttr = new WXAttr(); wxAttr.skipFilterPutAll(attr); if (mBindingAttrs != null) { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java index 7a77fa9..5ee2456 100644 --- a/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java +++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java @@ -23,9 +23,11 @@ import android.support.v4.util.ArrayMap; import com.alibaba.fastjson.JSONObject; import com.taobao.weex.dom.binding.ELUtils; +import com.taobao.weex.dom.binding.JSONUtils; import java.io.Serializable; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; /** @@ -95,20 +97,22 @@ public class WXEvent extends ArrayList<String> implements Serializable, Cloneabl public void addEvent(Object event) { if(event instanceof CharSequence){ + if(JSONUtils.isJSON(event.toString())){ + addEvent(JSONUtils.toJSON(event.toString())); + return; + } String eventName = event.toString(); if(!contains(eventName)){ add(eventName); } }else if(event instanceof JSONObject){ JSONObject bindings = (JSONObject) event; - String eventName = bindings.getString(WXEvent.EVENT_KEY_TYPE); - Object args = bindings.get(WXEvent.EVENT_KEY_ARGS); - if (eventName != null) { - putEventBindingArgs(eventName, args); - } + addBindingEvent(bindings); } } + + public static String getEventName(Object event){ if(event instanceof CharSequence){ return event.toString(); @@ -123,15 +127,38 @@ public class WXEvent extends ArrayList<String> implements Serializable, Cloneabl return event.toString(); } - public void putEventBindingArgs(String event, Object args){ - if(!contains(event)){ - add(event); + + public void parseStatements() { + if(!isEmpty()){ + for(int i=0; i<size(); i++){ + String event = get(i); + if(JSONUtils.isJSON(event)){ + JSONObject object = JSONUtils.toJSON(event); + String eventName = addBindingEvent(object); + set(i, eventName); + } + } + } + } + + private String addBindingEvent(JSONObject bindings){ + String eventName = bindings.getString(WXEvent.EVENT_KEY_TYPE); + Object args = bindings.get(WXEvent.EVENT_KEY_ARGS); + if (eventName != null) { + addBindingArgsEvent(eventName, args); + } + return eventName; + } + + private void addBindingArgsEvent(String eventName, Object args){ + if(!contains(eventName)){ + add(eventName); } if(args != null){ if(mEventBindingArgs == null){ mEventBindingArgs = new ArrayMap(); } - mEventBindingArgs.put(event, ELUtils.bindingBlock(args)); + mEventBindingArgs.put(eventName, ELUtils.bindingBlock(args)); } } @@ -156,4 +183,6 @@ public class WXEvent extends ArrayList<String> implements Serializable, Cloneabl event.mEventBindingArgsValues = null; //this should not be clone, it dynamic args return event; } + + } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java index 393a435..2a317d5 100644 --- a/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java +++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java @@ -45,7 +45,7 @@ public class WXStyle implements Map<String, Object>,Cloneable { public static final int UNSET = -1; @NonNull - private final Map<String,Object> mStyles; + private Map<String,Object> mStyles; @Nullable private Map<String,Map<String,Object>> mPesudoStyleMap;// clz_group:{styleMap} @@ -69,7 +69,7 @@ public class WXStyle implements Map<String, Object>,Cloneable { public WXStyle(Map<String, Object> mStyles, boolean byPesudo) { this(); - this.putAll(filterBindingStyles(mStyles), byPesudo); + this.putAll(mStyles, byPesudo); } @Nullable @@ -360,6 +360,9 @@ public class WXStyle implements Map<String, Object>,Cloneable { @Override public Object put(String key, Object value) { + if(addBindingStyleIfStatement(key, value)){ + return null; + } return mStyles.put(key,value); } @@ -380,6 +383,11 @@ public class WXStyle implements Map<String, Object>,Cloneable { } } + public void updateStyle(Map<? extends String, ?> map, boolean byPesudo){ + parseBindingStylesStatements(map); + putAll(map, byPesudo); + } + public Map<String, Object> getPesudoResetStyles() { if(mPesudoResetStyleMap == null){ @@ -447,26 +455,7 @@ public class WXStyle implements Map<String, Object>,Cloneable { return mStyles.values(); } - @Override - protected WXStyle clone(){ - WXStyle style = new WXStyle(); - style.mStyles.putAll(this.mStyles); - - if(mPesudoStyleMap != null) { - style.mPesudoStyleMap = new ArrayMap<>(); - for (Entry<String, Map<String, Object>> entry : this.mPesudoStyleMap.entrySet()) { - Map<String, Object> valueClone = new ArrayMap<>(); - valueClone.putAll(entry.getValue()); - style.mPesudoStyleMap.put(entry.getKey(), valueClone); - } - } - if(mPesudoResetStyleMap!=null) { - style.mPesudoResetStyleMap = new ArrayMap<>(); - style.mPesudoResetStyleMap.putAll(this.mPesudoResetStyleMap); - } - return style; - } private void initPesudoMapsIfNeed(Map<? extends String, ?> styles){ if(mPesudoStyleMap == null){ @@ -480,10 +469,18 @@ public class WXStyle implements Map<String, Object>,Cloneable { } } + + + public void parseStatements(){ + if(this.mStyles != null){ + this.mStyles = parseBindingStylesStatements(this.mStyles); + } + } + /** * filter dynamic state ment * */ - private Map<String, Object> filterBindingStyles(Map styles) { + private Map<String, Object> parseBindingStylesStatements(Map styles) { if(styles == null || styles.size() == 0){ return styles; } @@ -491,7 +488,13 @@ public class WXStyle implements Map<String, Object>,Cloneable { Iterator<Entry<String,Object>> it = entries.iterator(); while (it.hasNext()){ Map.Entry<String,Object> entry = it.next(); - if(filterBindingStyle(entry.getKey(), entry.getValue())){ + if(addBindingStyleIfStatement(entry.getKey(), entry.getValue())){ + if(mPesudoStyleMap != null){ + mPesudoStyleMap.remove(entry.getKey()); + } + if(mPesudoResetStyleMap != null){ + mPesudoResetStyleMap.remove(entry.getKey()); + } it.remove(); } } @@ -501,7 +504,7 @@ public class WXStyle implements Map<String, Object>,Cloneable { /** * filter dynamic attrs and statements * */ - private boolean filterBindingStyle(String key, Object value) { + private boolean addBindingStyleIfStatement(String key, Object value) { if(ELUtils.isBinding(value)){ if(mBindingStyle == null){ mBindingStyle = new ArrayMap<String, Object>(); @@ -516,4 +519,30 @@ public class WXStyle implements Map<String, Object>,Cloneable { public ArrayMap<String, Object> getBindingStyle() { return mBindingStyle; } + + @Override + public WXStyle clone(){ + WXStyle style = new WXStyle(); + style.mStyles.putAll(this.mStyles); + if(mBindingStyle != null){ + style.mBindingStyle = new ArrayMap<>(mBindingStyle); + } + if(mPesudoStyleMap != null) { + style.mPesudoStyleMap = new ArrayMap<>(); + for (Entry<String, Map<String, Object>> entry : this.mPesudoStyleMap.entrySet()) { + Map<String, Object> valueClone = new ArrayMap<>(); + valueClone.putAll(entry.getValue()); + style.mPesudoStyleMap.put(entry.getKey(), valueClone); + } + } + + if(mPesudoResetStyleMap!=null) { + style.mPesudoResetStyleMap = new ArrayMap<>(); + style.mPesudoResetStyleMap.putAll(this.mPesudoResetStyleMap); + } + + + return style; + } + } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/dom/binding/ELUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/binding/ELUtils.java b/android/sdk/src/main/java/com/taobao/weex/dom/binding/ELUtils.java index dac03b2..390b611 100644 --- a/android/sdk/src/main/java/com/taobao/weex/dom/binding/ELUtils.java +++ b/android/sdk/src/main/java/com/taobao/weex/dom/binding/ELUtils.java @@ -18,6 +18,7 @@ */ package com.taobao.weex.dom.binding; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.taobao.weex.WXEnvironment; @@ -60,6 +61,8 @@ public class ELUtils { return true; } } + }else if(value instanceof String){ + return ((String) value).indexOf(BINDING) >= 0; } return false; } @@ -92,6 +95,13 @@ public class ELUtils { for(int i=0; i<array.size(); i++){ bindingBlock(array.get(i)); } + }else if(value instanceof String){ + String json = value.toString(); + if(json.startsWith("{")){ + return bindingBlock(JSON.parseObject(json)); + }else if(json.startsWith("[")){ + return bindingBlock(JSON.parseArray(json)); + } } return value; } @@ -104,6 +114,8 @@ public class ELUtils { ((JSONObject) vfor).put(WXStatement.WX_FOR_LIST, Parser.parse(list.toString())); } } + }else if(vfor instanceof String){ + return vforBlock(JSONObject.parseObject(vfor.toString())); }else{ if(WXEnvironment.isApkDebugable()){ WXLogUtils.e("weex", "weex vfor is illegal " + vfor); @@ -112,5 +124,4 @@ public class ELUtils { return vfor; } - } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/dom/binding/JSONUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/binding/JSONUtils.java b/android/sdk/src/main/java/com/taobao/weex/dom/binding/JSONUtils.java new file mode 100644 index 0000000..30d72d5 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/dom/binding/JSONUtils.java @@ -0,0 +1,51 @@ +/** + * 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.dom.binding; + +import com.alibaba.fastjson.JSONObject; + +/** + * Created by furture on 2018/5/8. + */ + +public class JSONUtils { + + + public static boolean isJSON(Object json){ + if(json instanceof JSONObject){ + return true; + } + if(json instanceof String){ + return ((String) json).startsWith("{"); + } + return false; + } + + public static JSONObject toJSON(Object json){ + if(json instanceof JSONObject){ + return (JSONObject) json; + } + return JSONObject.parseObject(json.toString()); + } + + + public static boolean isJSON(String json){ + return json.startsWith("{"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java ---------------------------------------------------------------------- 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 b544cb9..e70af17 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 @@ -26,6 +26,7 @@ import com.taobao.weex.dom.CSSShorthand; import com.taobao.weex.dom.WXAttr; import com.taobao.weex.dom.WXEvent; import com.taobao.weex.dom.WXStyle; +import com.taobao.weex.ui.component.list.template.jni.NativeRenderObjectUtils; import com.taobao.weex.utils.WXUtils; import java.util.Map; @@ -42,6 +43,7 @@ public class BasicComponentData<T extends View> { private CSSShorthand mMargins; private CSSShorthand mPaddings; private CSSShorthand mBorders; + private long renderObjectPr = 0; public BasicComponentData(String ref, String componentType, String parentRef) { this.mRef = ref; @@ -262,4 +264,45 @@ public class BasicComponentData<T extends View> { public final void setBorders(@NonNull CSSShorthand mBorders) { this.mBorders = mBorders; } + + + + @Override + public BasicComponentData clone() throws CloneNotSupportedException { + BasicComponentData basicComponentData = new BasicComponentData(mRef, mComponentType, mParentRef); + basicComponentData.setBorders(getBorder().clone()); + basicComponentData.setMargins(getMargin().clone()); + basicComponentData.setPaddings(getPadding().clone()); + if(mAttributes != null){ + basicComponentData.mAttributes = mAttributes.clone(); + } + if(mStyles != null){ + basicComponentData.mStyles = mStyles.clone(); + } + if(mEvents != null){ + basicComponentData.mEvents = mEvents.clone(); + } + + if(renderObjectPr != 0){ + basicComponentData.setRenderObjectPr(NativeRenderObjectUtils.nativeCopyRenderObject(renderObjectPr)); + } + return basicComponentData; + } + + public long getRenderObjectPr() { + return renderObjectPr; + } + + public boolean isRenderPtrEmpty(){ + return renderObjectPr == 0; + } + + public synchronized void setRenderObjectPr(long renderObjectPr) { + if(this.renderObjectPr != renderObjectPr){ + if(this.renderObjectPr != 0){ + throw new RuntimeException("RenderObjectPr has " + renderObjectPr + " old renderObjectPtr " + this.renderObjectPr); + } + this.renderObjectPr = renderObjectPr; + } + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java ---------------------------------------------------------------------- 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 aa60a73..347b7fa 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 @@ -100,7 +100,7 @@ public class GraphicActionAddElement extends GraphicActionAbstractAddElement { long start = System.currentTimeMillis(); if(layoutPosition !=null && layoutSize != null) { - child.updateDemission(layoutSize, layoutPosition); + child.setDemission(layoutSize, layoutPosition); } child.applyLayoutAndEvent(child); WXSDKManager.getInstance().getSDKInstance(getPageId()).callLayoutaAplyLayoutAndEventTime(System.currentTimeMillis() - start); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java ---------------------------------------------------------------------- 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 777df14..693096a 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 class GraphicActionLayout extends BasicGraphicAction { } long start = System.currentTimeMillis(); - component.updateDemission(mLayoutSize, mLayoutPosition); + component.setDemission(mLayoutSize, mLayoutPosition); WXSDKManager.getInstance().getSDKInstance(getPageId()).callLayoutUpdateDemissionTime(System.currentTimeMillis() - start); component.setLayout(component); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java ---------------------------------------------------------------------- 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 fffed20..31b52fd 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 @@ -57,7 +57,7 @@ public class GraphicActionUpdateStyle extends BasicGraphicAction { return; } if (null != mStyle) { - component.addStyle(mStyle, mIsCausedByPesudo); + component.updateStyle(mStyle, mIsCausedByPesudo); if(style.containsKey(Constants.Name.TRANSFORM) && component.getTransition() == null) { Map<String, Object> animationMap = new ArrayMap<>(2); animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java index 9cb0e2d..9837809 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java @@ -63,4 +63,12 @@ public class GraphicPosition { public void setBottom(float bottom) { this.mBottom = bottom; } + + + public void update(float top, float bottom, float left, float right) { + this.mTop = top; + this.mBottom = bottom; + this.mLeft = left; + this.mRight = right; + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java index 371b196..35d6439 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java @@ -43,4 +43,9 @@ public class GraphicSize { public void setHeight(float height) { this.mHeight = height; } + + public void update(float width, float height) { + this.mWidth = width; + this.mHeight = height; + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java ---------------------------------------------------------------------- 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 new file mode 100644 index 0000000..8e69f47 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/UpdateComponentDataAction.java @@ -0,0 +1,69 @@ +/** + * 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.text.TextUtils; + +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.bridge.SimpleJSCallback; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.list.template.CellDataManager; +import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList; +import com.taobao.weex.utils.WXLogUtils; + + +/** + * Created by furture on 2018/1/23. + */ + +public class UpdateComponentDataAction extends BasicGraphicAction{ + + private String virtualComponentId; + private JSONObject data; + private String callback; + + + public UpdateComponentDataAction(String pageId, String virtualComponentId, + JSONObject data, String callback) { + super(pageId, CellDataManager.getListRef(virtualComponentId)); + this.virtualComponentId = virtualComponentId; + this.data = data; + this.callback = callback; + } + + @Override + public void executeAction() { + if(TextUtils.isEmpty(getRef())){ + WXLogUtils.e("wrong virtualComponentId split error " + virtualComponentId); + return; + } + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if(component instanceof WXRecyclerTemplateList){ + WXRecyclerTemplateList templateList = (WXRecyclerTemplateList) component; + templateList.getCellDataManager().updateVirtualComponentData(virtualComponentId, data); + templateList.notifyUpdateList(); + SimpleJSCallback jsCallback = new SimpleJSCallback(component.getInstanceId(), callback); + jsCallback.invoke(true); + }else{ + WXLogUtils.e("recycler-list wrong virtualComponentId " + virtualComponentId); + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/ComponentUtils.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/ComponentUtils.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/ComponentUtils.java deleted file mode 100644 index 373d9cd..0000000 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/ComponentUtils.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * 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; - -import com.taobao.weex.WXEnvironment; -import com.taobao.weex.WXSDKManager; -import com.taobao.weex.utils.WXLogUtils; - -/** - * Created by furture on 2018/1/25. - */ - -public class ComponentUtils { - - private static final String TAG = "ComponentUtils"; - - /** - * init component if component is lazy, - * if component is not lazy, do nothing - * */ - public static void initLazyComponent(WXComponent component, WXVContainer mParent){ - if(component.isLazy()){ - component.lazy(false); - if(mParent != null){ - int index = mParent.indexOf(component); - mParent.createChildViewAt(index); - }else { - component.createView(); - } - component.applyLayoutAndEvent(component); - component.bindData(component); - } - } - - /** - * build component tree and dom tree for template list - * */ - // TODO -// public static synchronized final WXComponent buildTree(WXDomObject domObject, WXVContainer parent){ -// DOMActionContext domActionContext = WXSDKManager.getInstance().getWXDomManager().getDomContext(parent.getInstanceId()); -// if(domActionContext == null){ -// return null; -// } -// DomTreeBuilder builder = new DomTreeBuilder(); -// domObject.traverseTree( -// domActionContext.getAddDOMConsumer(), -// domActionContext.getApplyStyleConsumer() -// ); -// return builder.buildComponentTree(domActionContext, domObject, parent); -// } - - - /** - * dom tree build - * */ - // TODO -// static class DomTreeBuilder extends TraceableAction { -// -// private WXComponent buildComponentTree(DOMActionContext context, WXDomObject dom, WXVContainer parent) { -// if (dom == null) { -// return null; -// } -// long startNanos = System.nanoTime(); -// dom.setCloneThis(true); -// WXComponent component = WXComponentFactory.newInstance(context.getInstance(), dom, parent); -// if (component != null) { -// component.mTraceInfo.domThreadStart = dom.mDomThreadTimestamp; -// component.mTraceInfo.rootEventId = mTracingEventId; -// component.mTraceInfo.domQueueTime = mDomQueueTime; -// } -// context.registerComponent(dom.getRef(), component); -// if (component instanceof WXVContainer) { -// WXVContainer container = (WXVContainer) component; -// WXDomObject parentDom = (WXDomObject) container.getDomObject(); -// for (int i = 0; i < dom.childCount(); ++i) { -// WXDomObject child = dom.getChild(i); -// if (child != null) { -// WXComponent childComponent = buildComponentTree(context, child, container); -// container.addChild(childComponent); -// WXDomObject childDomObject = (WXDomObject) childComponent.getDomObject(); -// if(childDomObject != child) { -// int index = parentDom.index(child); -// parentDom.add(childDomObject, index); -// if(index >= 0) { -// parentDom.remove(child); -// i--; -// } -// RuntimeException exception = new IllegalArgumentException(childDomObject.getClass().getName() -// + " not support clone this"); -// WXLogUtils.e("weex", exception); -// if(WXEnvironment.isApkDebugable()){ -// throw exception; -// } -// } -// } -// } -// } -// dom.setCloneThis(false); -// if (component != null) { -// component.mTraceInfo.domThreadNanos = System.nanoTime() - startNanos; -// } -// return component; -// } -// } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java index ce47a6f..8c8b003 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java @@ -27,6 +27,7 @@ import java.lang.annotation.Target; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -99,6 +100,7 @@ import com.taobao.weex.ui.animation.WXAnimationBean; import com.taobao.weex.ui.animation.WXAnimationModule; import com.taobao.weex.ui.component.basic.WXBasicComponent; import com.taobao.weex.ui.component.binding.Statements; +import com.taobao.weex.ui.component.list.template.jni.NativeRenderObjectUtils; import com.taobao.weex.ui.component.pesudo.OnActivePseudoListner; import com.taobao.weex.ui.component.pesudo.PesudoStatus; import com.taobao.weex.ui.component.pesudo.TouchActivePseudoListener; @@ -219,7 +221,7 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple protected void setContentBoxMeasurement(final ContentBoxMeasurement contentBoxMeasurement) { this.contentBoxMeasurement = contentBoxMeasurement; - WXBridgeManager.getInstance().bindMeasurementToWXCore(getInstanceId(), getRef(), contentBoxMeasurement); + WXBridgeManager.getInstance().bindMeasurementToRenderObject(getRenderObjectPtr(), contentBoxMeasurement); } public void updateStyles(WXComponent component) { @@ -626,11 +628,25 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple } } - public void updateDemission(GraphicSize size, GraphicPosition position) { + public void setDemission(GraphicSize size, GraphicPosition position) { setLayoutPosition(position); setLayoutSize(size); } + public void updateDemission(float top, float bottom, float left, float right, float height, float width) { + getLayoutPosition().update(top, bottom, left, right); + getLayoutSize().update(width, height); + } + + + public void applyLayoutOnly(){ + if(!isLazy()) { + setLayout(this); + setPadding(this.getPadding(), this.getBorder()); + } + } + + public void refreshData(WXComponent component) { } @@ -2073,7 +2089,11 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple public void setWaste(boolean waste) { if(this.waste != waste){ this.waste = waste; - if(waste){ + if(!WXBasicComponentType.RECYCLE_LIST.equals(getParent().getComponentType())){ + NativeRenderObjectUtils.nativeRenderObjectChildWaste(getRenderObjectPtr(), waste); + } + + if(waste){ //update dom not show, and put style to hidden getStyles().put(Constants.Name.VISIBILITY, Constants.Value.HIDDEN); //if component not init, mark lazy init when use, reduce view count @@ -2085,13 +2105,13 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple getHostView().setVisibility(View.GONE); } }else{ - getStyles().put(Constants.Name.VISIBILITY, Constants.Value.VISIBLE); + getStyles().put(Constants.Name.VISIBILITY, Constants.Value.VISIBLE); if(getHostView() == null){ if(mLazy) { // when parent is lazy just mark node lazy false if(mParent != null && mParent.isLazy()){ lazy(false); }else{ - ComponentUtils.initLazyComponent(this, mParent); + Statements.initLazyComponent(this, mParent); } } }else{ @@ -2182,4 +2202,65 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple public void lazy(boolean lazy) { mLazy = lazy; } + + public long getRenderObjectPtr(){ + if(getBasicComponentData().isRenderPtrEmpty()){ + getBasicComponentData().setRenderObjectPr(NativeRenderObjectUtils.nativeGetRenderObject(getInstanceId(), getRef())); + } + return getBasicComponentData().getRenderObjectPr(); + } + + + public void updateNativeAttr(String key, Object value){ + if(key == null){ + return; + } + if(value == null){ + value = ""; + } + getBasicComponentData().getAttrs().put(key, value); + NativeRenderObjectUtils.nativeUpdateRenderObjectAttr(getRenderObjectPtr(), key, value.toString()); + } + + public void nativeUpdateAttrs(Map<String, Object> dynamic){ + Set<Map.Entry<String, Object>> entries = dynamic.entrySet(); + /** + * diff attrs, see attrs has update, remove none update attrs + * */ + Iterator<Map.Entry<String, Object>> iterator = entries.iterator(); + while (iterator.hasNext()){ + Map.Entry<String, Object> objectEntry = iterator.next(); + if(objectEntry.getKey() == null){ + continue; + } + updateNativeAttr(objectEntry.getKey(), objectEntry.getValue()); + } + } + + + public void updateNativeStyle(String key, Object value){ + if(key == null){ + return; + } + if(value == null){ + value = ""; + } + getBasicComponentData().getStyles().put(key, value); + NativeRenderObjectUtils.nativeUpdateRenderObjectStyle(getRenderObjectPtr(), key, value.toString()); + } + + public void updateNativeStyles(Map<String, Object> dynamic){ + Set<Map.Entry<String, Object>> entries = dynamic.entrySet(); + /** + * diff attrs, see attrs has update, remove none update attrs + * */ + Iterator<Map.Entry<String, Object>> iterator = entries.iterator(); + while (iterator.hasNext()){ + Map.Entry<String, Object> objectEntry = iterator.next(); + if(objectEntry.getKey() == null){ + continue; + } + updateNativeStyle(objectEntry.getKey(), objectEntry.getValue()); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java index 67296a0..6452559 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/basic/WXBasicComponent.java @@ -27,6 +27,7 @@ import com.taobao.weex.dom.WXStyle; 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.WXBasicComponentType; import com.taobao.weex.ui.component.WXComponent; import java.util.Map; import java.util.Set; @@ -129,6 +130,13 @@ public abstract class WXBasicComponent<T extends View> { mBasicComponentData.addStyle(styles, byPesudo); } + public final void updateStyle(Map<String, Object> styles, boolean byPesudo){ + if (styles == null || styles.isEmpty()) { + return; + } + mBasicComponentData.getStyles().updateStyle(styles, byPesudo); + } + public final void addEvent(Set<String> events) { if (events == null || events.isEmpty()) { return; @@ -167,7 +175,7 @@ public abstract class WXBasicComponent<T extends View> { return mRef; } - protected GraphicPosition getLayoutPosition() { + public GraphicPosition getLayoutPosition() { if (mLayoutPosition == null) { mLayoutPosition = new GraphicPosition(0, 0, 0, 0); } @@ -178,7 +186,7 @@ public abstract class WXBasicComponent<T extends View> { this.mLayoutPosition = mLayoutPosition; } - protected GraphicSize getLayoutSize() { + public GraphicSize getLayoutSize() { if (mLayoutSize == null) { mLayoutSize = new GraphicSize(0, 0); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java new file mode 100644 index 0000000..9f99925 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/AsynLayoutTask.java @@ -0,0 +1,60 @@ +/** + * 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.binding; + +import android.os.AsyncTask; + +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.list.template.TemplateViewHolder; + +/** + * Created by furture on 2018/5/11. + */ + +class AsynLayoutTask extends AsyncTask<Void, Void, Void> { + + private final TemplateViewHolder templateViewHolder; + private final int position; + private final WXComponent component; + + AsynLayoutTask(TemplateViewHolder templateViewHolder, int position, WXComponent component) { + this.templateViewHolder = templateViewHolder; + this.position = position; + this.component = component; + } + + @Override + protected Void doInBackground(Void... params) { + if(templateViewHolder.getHolderPosition() == position){ + if(component.getInstance() != null && !component.getInstance().isDestroy()) { + Layouts.doLayoutOnly(component, templateViewHolder); + } + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + if(position == templateViewHolder.getHolderPosition()) { + if(component.getInstance() != null && !component.getInstance().isDestroy()) { + Layouts.setLayout(component, false); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java index e9307bb..bdbcea9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Layouts.java @@ -21,14 +21,16 @@ package com.taobao.weex.ui.component.binding; import android.os.AsyncTask; +import android.util.Log; import com.taobao.weex.WXEnvironment; -import com.taobao.weex.WXSDKInstance; import com.taobao.weex.common.Constants; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXVContainer; +import com.taobao.weex.ui.component.list.WXCell; import com.taobao.weex.ui.component.list.template.TemplateViewHolder; import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList; +import com.taobao.weex.ui.component.list.template.jni.NativeRenderObjectUtils; import com.taobao.weex.utils.WXLogUtils; /** @@ -47,60 +49,45 @@ public class Layouts { templateViewHolder.asyncTask = null; } if(async){ - AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() { - @Override - protected Void doInBackground(Void... params) { - if(templateViewHolder.getHolderPosition() == position){ - if(component.getInstance() != null && !component.getInstance().isDestroy()) { - doSafeLayout(component - // TODO -// , templateViewHolder.getLayoutContext() - ); - } - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - if(position == templateViewHolder.getHolderPosition()) { - if(component.getInstance() != null && !component.getInstance().isDestroy()) { - setLayout(component, false); - } - } - } - }; + AsyncTask<Void, Void, Void> asyncTask = new AsynLayoutTask(templateViewHolder, position, component); templateViewHolder.asyncTask = asyncTask; asyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); //serial executor is better }else{ - doSafeLayout(component -// , templateViewHolder.getLayoutContext() // TODO - ); + doLayoutOnly(component, templateViewHolder); setLayout(component, false); } } - /** - * safe layout + * @param layoutHeight height + * @param layoutWidth width * */ - public static void doSafeLayout(WXComponent component - // TODO -// , final CSSLayoutContext layoutContext - ){ + public static void doLayoutSync(WXCell component, float layoutWidth, float layoutHeight){ + doSafeLayout(component, layoutWidth, layoutHeight); + setLayout(component, false); + } + + /** + * safe layout + * */ + public static void doLayoutOnly(WXComponent component, TemplateViewHolder holder){ + doSafeLayout(component, holder.getTemplateList().getLayoutWidth(), holder.getTemplateList().getLayoutHeight()); + } + + private static void doSafeLayout(WXComponent component, float layoutWidth, float layoutHeight){ try{ long start = System.currentTimeMillis(); - doLayout(component -// , layoutContext - ); + int height = NativeRenderObjectUtils.nativeLayoutRenderObject(component.getRenderObjectPtr(), + layoutWidth, + layoutHeight); if(WXEnvironment.isOpenDebugLog() && WXRecyclerTemplateList.ENABLE_TRACE_LOG) { - WXLogUtils.d(WXRecyclerTemplateList.TAG, "WXTemplateList doSafeLayout" + - component.getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE) + Thread.currentThread().getName() + " doSafeLayout used " + + WXLogUtils.d(WXRecyclerTemplateList.TAG, "WXTemplateList doSafeLayout " + + component.getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE) + " " + Thread.currentThread().getName() + " doSafeLayout used " + (System.currentTimeMillis() - start)); } - if(!(component.getLayoutHeight() > 0)){ + if(!(height > 0)){ WXLogUtils.e(WXRecyclerTemplateList.TAG, " WXTemplateList doSafeLayout wrong template " + - component.getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE) + " cell height " + component.getLayoutHeight()); + component.getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE) + " cell height " + height); } }catch (Exception e){ if(WXEnvironment.isApkDebugable()){ @@ -109,48 +96,6 @@ public class Layouts { } } - private static void doLayout(WXComponent component -// , final CSSLayoutContext layoutContext - ){ - // TODO -// WXDomObject domObject = (WXDomObject) component.getDomObject(); -// final WXSDKInstance instance = component.getInstance(); -// domObject.traverseUpdateTree(new WXDomObject.Consumer() { -// @Override -// public void accept(WXDomObject dom) { -// if(instance == null || instance.isDestroy()){ -// return; -// } -// if(!dom.hasUpdate()){ -// return; -// } -// if(!dom.isShow()){ //not show just skip -// return; -// } -// dom.layoutBefore(); -// } -// }); -// if(instance != null && !instance.isDestroy()){ -// domObject.markDirty(layoutContext); -// } -// domObject.traverseUpdateTree( new WXDomObject.Consumer() { -// @Override -// public void accept(WXDomObject dom) { -// if(instance == null || instance.isDestroy()){ -// return; -// } -// if(!dom.isShow()){ -// return; -// } -// if (dom.hasUpdate()) { -// dom.layoutAfter(); -// } -// } -// }); - } - - - /** * recursive set layout to component, @@ -161,46 +106,17 @@ public class Layouts { if(component.isWaste()){ return; } - // TODO -// WXDomObject domObject = (WXDomObject) component.getDomObject(); -// if(domObject.hasUpdate() || force){ -// domObject.markUpdateSeen(); -// if(domObject.hasUpdate()){ -// domObject.markLayoutStateUpdated(); -// } -// component.setLayout(component.getDomObject()); -// if(component.getDomObject().getExtra() != null){ -// component.updateExtra(component.getDomObject().getExtra()); -// } -// } - if(component instanceof WXVContainer){ - WXVContainer container = (WXVContainer) component; - int count = container.getChildCount(); - for (int i = 0; i < count; ++i) { - WXComponent child = container.getChild(i); - if (child != null) { - setLayout(child, force); - } - } + long ptr = component.getRenderObjectPtr(); + if(NativeRenderObjectUtils.nativeRenderObjectHasNewLayout(ptr)){ + NativeRenderObjectUtils.nativeRenderObjectUpdateComponent(ptr, component); } - } - - private static final void setLayoutWaste(WXComponent component, boolean force){ - // TODO -// WXDomObject domObject = (WXDomObject) component.getDomObject(); -// if(domObject.hasUpdate() || force){ -// domObject.markUpdateSeen(); -// if(domObject.hasUpdate()){ -// domObject.markLayoutStateUpdated(); -// } -// } if(component instanceof WXVContainer){ WXVContainer container = (WXVContainer) component; int count = container.getChildCount(); for (int i = 0; i < count; ++i) { WXComponent child = container.getChild(i); if (child != null) { - setLayoutWaste(child, force); + setLayout(child, force); } } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java index 0448029..2e1cb92 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/binding/Statements.java @@ -32,10 +32,14 @@ import com.taobao.weex.dom.WXAttr; import com.taobao.weex.dom.WXEvent; import com.taobao.weex.dom.WXStyle; import com.taobao.weex.dom.binding.ELUtils; +import com.taobao.weex.dom.binding.JSONUtils; import com.taobao.weex.dom.binding.WXStatement; import com.taobao.weex.el.parse.ArrayStack; import com.taobao.weex.el.parse.Operators; import com.taobao.weex.el.parse.Token; +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.WXComponentFactory; import com.taobao.weex.ui.component.WXImage; @@ -45,6 +49,7 @@ import com.taobao.weex.ui.component.list.template.CellDataManager; import com.taobao.weex.ui.component.list.template.CellRenderContext; import com.taobao.weex.ui.component.list.template.VirtualComponentLifecycle; import com.taobao.weex.ui.component.list.template.WXRecyclerTemplateList; +import com.taobao.weex.ui.component.list.template.jni.NativeRenderObjectUtils; import com.taobao.weex.utils.WXLogUtils; import com.taobao.weex.utils.WXUtils; @@ -61,6 +66,52 @@ import java.util.Set; * simple statement execute, render component for template list */ public class Statements { + + + /** + * parse statements token from attrs and style and event + * */ + public static void parseStatementsToken(WXComponent component){ + if(component.getBasicComponentData().isRenderPtrEmpty()){ + component.getBasicComponentData().setRenderObjectPr(component.getRenderObjectPtr()); + } + if(component.getBasicComponentData() != null){ + BasicComponentData basicComponentData = component.getBasicComponentData(); + basicComponentData.getAttrs().parseStatements(); + basicComponentData.getStyles().parseStatements(); + basicComponentData.getEvents().parseStatements(); + } + if(component instanceof WXVContainer){ + WXVContainer container = (WXVContainer) component; + int count = container.getChildCount(); + for (int i = 0; i < count; ++i) { + parseStatementsToken(container.getChild(i)); + } + } + } + + + + /** + * init component if component is lazy, + * if component is not lazy, do nothing + * */ + public static void initLazyComponent(WXComponent component, WXVContainer mParent){ + if(component.isLazy() || component.getHostView() == null){ + component.lazy(false); + if(mParent != null){ + int index = mParent.indexOf(component); + mParent.createChildViewAt(index); + }else { + component.createView(); + } + component.applyLayoutAndEvent(component); + component.bindData(component); + } + } + + + /** * recursive copy component, none parent connect * */ @@ -73,16 +124,28 @@ public class Statements { * recursive copy component, * */ private static final WXComponent copyComponentTree(WXComponent source, WXVContainer parent){ - WXComponent component = WXComponentFactory.newInstance(source.getInstance(), parent, source.getBasicComponentData()); + BasicComponentData basicComponentData = null; + try { + basicComponentData = source.getBasicComponentData().clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + WXComponent component = WXComponentFactory.newInstance(source.getInstance(), parent, basicComponentData); + GraphicPosition graphicPosition = source.getLayoutPosition(); + GraphicSize graphicSize = source.getLayoutSize(); + component.updateDemission(graphicPosition.getTop(), graphicPosition.getBottom(), graphicPosition.getLeft(), graphicPosition.getRight(), + graphicSize.getHeight(), graphicSize.getWidth()); + component.updateExtra(source.getExtra()); if(source instanceof WXVContainer){ WXVContainer container = (WXVContainer) source; WXVContainer childParent = (WXVContainer) component; int count = container.getChildCount(); for (int i = 0; i < count; ++i) { - WXComponent child = container.getChild(i); - if (child != null) { - WXComponent targetChild = copyComponentTree(child, childParent); - childParent.addChild(targetChild); + WXComponent sourceChild = container.getChild(i); + if (sourceChild != null) { + WXComponent targetChild = copyComponentTree(sourceChild, childParent);childParent.addChild(targetChild); + NativeRenderObjectUtils.nativeAddChildRenderObject(childParent.getRenderObjectPtr(), + targetChild.getRenderObjectPtr()); } } } @@ -185,7 +248,7 @@ public class Statements { if(map == null){ key = index; value = item; - index++; + index ++; }else{ key = item; value = map.get(item); @@ -233,6 +296,8 @@ public class Statements { renderNode.getAttrs().getStatement().remove(WXStatement.WX_IF); //clear node's statement } parent.addChild(renderNode, renderIndex); + NativeRenderObjectUtils.nativeAddChildRenderObject(parent.getRenderObjectPtr(), + renderNode.getRenderObjectPtr()); updates.add(renderNode); if(WXEnvironment.isApkDebugable()){ WXLogUtils.d(WXRecyclerTemplateList.TAG, Thread.currentThread().getName() + renderNode.getRef() + renderNode.getComponentType() + "statements copy component tree used " + (System.currentTimeMillis() - start)); @@ -295,7 +360,7 @@ public class Statements { if(attr.get(ELUtils.IS_COMPONENT_ROOT) != null && WXUtils.getBoolean(attr.get(ELUtils.IS_COMPONENT_ROOT), false)){ if(attr.get(ELUtils.COMPONENT_PROPS) != null - && attr.get(ELUtils.COMPONENT_PROPS) instanceof JSONObject){ + && JSONUtils.isJSON(attr.get(ELUtils.COMPONENT_PROPS))){ String compoentId = (String) attr.get(CellDataManager.SUB_COMPONENT_TEMPLATE_ID); Object compoentData = null; if(!TextUtils.isEmpty(compoentId)){ @@ -303,7 +368,7 @@ public class Statements { if(virtualComponentId == null){ //none virtualComponentId, create and do attach virtualComponentId = CellDataManager.createVirtualComponentId(context.templateList.getRef(), component.getViewTreeKey(), context.templateList.getItemId(context.position)); - Map<String, Object> props = renderProps((JSONObject) attr.get(ELUtils.COMPONENT_PROPS), context.stack); + Map<String, Object> props = renderProps(JSONUtils.toJSON(attr.get(ELUtils.COMPONENT_PROPS)), context.stack); EventResult result = WXBridgeManager.getInstance().syncCallJSEventWithResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, compoentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.CREATE, new Object[]{ virtualComponentId, props @@ -367,8 +432,10 @@ public class Statements { doRenderBindingAttrsAndEvent(component, context); if(component instanceof WXVContainer){ - if(!(component instanceof WXCell)){ - return; + if(component.isWaste()){ + if(!(component instanceof WXCell)){ + return; + } } WXVContainer container = (WXVContainer) component; for(int k=0; k<container.getChildCount();){ @@ -431,7 +498,7 @@ public class Statements { //for image avoid dirty layout, only update src attrs component.getAttrs().put(Constants.Name.SRC, dynamic.get(Constants.Name.SRC)); }else { -// domObject.updateAttr(dynamic); //dirty layout + component.nativeUpdateAttrs(dynamic); } if(isMainThread()) { component.updateProperties(dynamic); @@ -467,9 +534,7 @@ public class Statements { } } if(dynamic.size() > 0) { - // TODO -// domObject.updateStyle(dynamic, false); -// domObject.applyStyle(dynamic); + component.updateNativeStyles(dynamic); if(isMainThread()) { component.updateProperties(dynamic); } @@ -598,8 +663,6 @@ public class Statements { return params; } - private static volatile int componentIdNext = 0; - private static boolean isMainThread(){ return Thread.currentThread() == Looper.getMainLooper().getThread(); @@ -625,4 +688,7 @@ public class Statements { } return getComponentId(component.getParent()); } + + + } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java index fb57c32..a147f03 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/BasicListComponent.java @@ -66,7 +66,6 @@ import com.taobao.weex.ui.view.listview.adapter.IOnLoadMoreListener; import com.taobao.weex.ui.view.listview.adapter.IRecyclerAdapterListener; import com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder; import com.taobao.weex.ui.view.listview.adapter.RecyclerViewBaseAdapter; -import com.taobao.weex.ui.view.listview.adapter.TransformItemDecoration; import com.taobao.weex.ui.view.listview.adapter.WXRecyclerViewOnScrollListener; import com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView; import com.taobao.weex.utils.WXLogUtils; @@ -81,7 +80,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -98,8 +96,8 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView private static final Pattern transformPattern = Pattern.compile("([a-z]+)\\(([0-9\\.]+),?([0-9\\.]+)?\\)"); private Map<String, AppearanceHelper> mAppearComponents = new HashMap<>(); - private Runnable mAppearComponentsRunnable = null; - private long mAppearDelay = 50; + private Runnable mAppearChangeRunnable = null; + private long mAppearChangeRunnableDelay = 50; private boolean isScrollable = true; private ArrayMap<String, Long> mRefToViewType; @@ -226,9 +224,9 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView @Override public void destroy() { - if(mAppearComponentsRunnable != null) { - getHostView().removeCallbacks(mAppearComponentsRunnable); - mAppearComponentsRunnable = null; + if(mAppearChangeRunnable != null) { + getHostView().removeCallbacks(mAppearChangeRunnable); + mAppearChangeRunnable = null; } super.destroy(); if (mStickyMap != null) @@ -269,7 +267,7 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView keepPositionLayoutDelay = WXUtils.getNumberInt(getAttrs().get(Constants.Name.KEEP_POSITION_LAYOUT_DELAY), (int)keepPositionLayoutDelay); } if(getAttrs().get("appearActionDelay") != null){ - mAppearDelay = WXUtils.getNumberInt(getAttrs().get("appearActionDelay"), (int)mAppearDelay); + mAppearChangeRunnableDelay = WXUtils.getNumberInt(getAttrs().get("appearActionDelay"), (int) mAppearChangeRunnableDelay); } mItemAnimator=bounceRecyclerView.getInnerView().getItemAnimator(); @@ -466,19 +464,19 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView @Override public void bindAppearEvent(WXComponent component) { setAppearanceWatch(component, AppearanceHelper.APPEAR, true); - if(mAppearComponentsRunnable == null){ - mAppearComponentsRunnable = new Runnable() { + if(mAppearChangeRunnable == null){ + mAppearChangeRunnable = new Runnable() { @Override public void run() { - if(mAppearComponentsRunnable != null) { + if(mAppearChangeRunnable != null) { notifyAppearStateChange(0, 0, 0, 0); } } }; } if (getHostView() != null) { - getHostView().removeCallbacks(mAppearComponentsRunnable); - getHostView().postDelayed(mAppearComponentsRunnable, mAppearDelay); + getHostView().removeCallbacks(mAppearChangeRunnable); + getHostView().postDelayed(mAppearChangeRunnable, mAppearChangeRunnableDelay); } } @@ -1200,9 +1198,9 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView @Override public void notifyAppearStateChange(int firstVisible, int lastVisible, int directionX, int directionY) { - if(mAppearComponentsRunnable != null) { - getHostView().removeCallbacks(mAppearComponentsRunnable); - mAppearComponentsRunnable = null; + if(mAppearChangeRunnable != null) { + getHostView().removeCallbacks(mAppearChangeRunnable); + mAppearChangeRunnable = null; } //notify appear state Iterator<AppearanceHelper> it = mAppearComponents.values().iterator(); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java index d6df19e..a30a1ac 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXCell.java @@ -18,8 +18,6 @@ */ package com.taobao.weex.ui.component.list; -import static com.taobao.weex.common.Constants.Name.STICKY_OFFSET; - import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; @@ -27,6 +25,7 @@ import android.support.annotation.RestrictTo; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; + import com.taobao.weex.WXSDKInstance; import com.taobao.weex.annotation.Component; import com.taobao.weex.common.Constants; @@ -38,8 +37,11 @@ import com.taobao.weex.ui.view.WXFrameLayout; import com.taobao.weex.utils.WXLogUtils; import com.taobao.weex.utils.WXUtils; import com.taobao.weex.utils.WXViewUtils; + import java.util.LinkedList; +import static com.taobao.weex.common.Constants.Name.STICKY_OFFSET; + /** * Root component for components in {@link WXListComponent} */ @@ -61,6 +63,10 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { private boolean isSourceUsed = false; + private boolean isAppendTreeDone; + + private CellAppendTreeListener cellAppendTreeListener; + @Deprecated public WXCell(WXSDKInstance instance, WXVContainer parent, String instanceId, boolean isLazy, BasicComponentData basicComponentData) { super(instance, parent, basicComponentData); @@ -224,4 +230,29 @@ public class WXCell extends WidgetContainer<WXFrameLayout> { public void setSourceUsed(boolean sourceUsed) { isSourceUsed = sourceUsed; } + + + public boolean isAppendTreeDone(){ + return isAppendTreeDone; + } + + @Override + public void appendTreeCreateFinish() { + super.appendTreeCreateFinish(); + isAppendTreeDone = true; + if(cellAppendTreeListener != null){ + cellAppendTreeListener.onAppendTreeDone(); + } + } + + public void setCellAppendTreeListener(CellAppendTreeListener cellAppendTreeListener) { + this.cellAppendTreeListener = cellAppendTreeListener; + if(isAppendTreeDone){ + cellAppendTreeListener.onAppendTreeDone(); + } + } + + public interface CellAppendTreeListener{ + public void onAppendTreeDone(); + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java index 3519db2..feca9f9 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/WXListComponent.java @@ -97,9 +97,9 @@ public class WXListComponent extends BasicListComponent<BounceRecyclerView> { } private boolean hasColumnPros() { - return mColumnWidth != WXUtils.parseFloat(getAttrs().get(Constants.Name.COLUMN_WIDTH)) || - mColumnCount != WXUtils.parseInt(getAttrs().get(Constants.Name.COLUMN_COUNT)) || - mColumnGap != WXUtils.parseFloat(getAttrs().get(Constants.Name.COLUMN_GAP)); + return (getAttrs().containsKey(Constants.Name.COLUMN_WIDTH) && mColumnWidth != WXUtils.parseFloat(getAttrs().get(Constants.Name.COLUMN_WIDTH))) || + (getAttrs().containsKey(Constants.Name.COLUMN_COUNT) && mColumnCount != WXUtils.parseInt(getAttrs().get(Constants.Name.COLUMN_COUNT))) || + (getAttrs().containsKey(Constants.Name.COLUMN_GAP) && mColumnGap != WXUtils.parseFloat(getAttrs().get(Constants.Name.COLUMN_GAP))); } /** http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java index 0dae3c8..d186c81 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/AsyncCellLoadTask.java @@ -59,6 +59,7 @@ class AsyncCellLoadTask extends AsyncTask<Void,Void, Void> { WXCell component = (WXCell) templateList.copyComponentFromSourceCell(source); if(WXEnvironment.isOpenDebugLog() && WXRecyclerTemplateList.ENABLE_TRACE_LOG){ WXLogUtils.d(WXRecyclerTemplateList.TAG, " AsyncCellLoadTask load " + template + + " " + component.hashCode() + " used " + (System.currentTimeMillis() - start)); } if(component == null){ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/PositionRef.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/PositionRef.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/PositionRef.java index f25c9a9..d176302 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/PositionRef.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/PositionRef.java @@ -18,11 +18,14 @@ */ package com.taobao.weex.ui.component.list.template; +import com.alibaba.fastjson.JSONAware; +import com.alibaba.fastjson.annotation.JSONType; + /** * position render state, when render state change, position changed * Created by furture on 2018/2/2. */ -public class PositionRef extends Number{ +public class PositionRef extends Number implements JSONAware { private CellRenderState renderState; @@ -61,4 +64,9 @@ public class PositionRef extends Number{ public String toString() { return String.valueOf(getPosition()); } + + @Override + public String toJSONString() { + return String.valueOf(getPosition()); + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b049f80e/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java index ac69c51..c0d4fb0 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/TemplateViewHolder.java @@ -17,8 +17,10 @@ * under the License. */ package com.taobao.weex.ui.component.list.template; + import android.os.AsyncTask; import android.view.View; + import com.taobao.weex.ui.component.list.WXCell; import com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder; @@ -33,8 +35,7 @@ public class TemplateViewHolder extends ListBaseViewHolder { * */ private WXCell template; - // TODO -// private CSSLayoutContext layoutContext; + private WXRecyclerTemplateList templateList; private int holderPosition = -1; @@ -46,26 +47,18 @@ public class TemplateViewHolder extends ListBaseViewHolder { * header position * */ - public TemplateViewHolder(WXCell component, int viewType) { + public TemplateViewHolder(WXRecyclerTemplateList templateList, WXCell component, int viewType) { super(component, viewType); this.template = component; + this.templateList = templateList; } - public TemplateViewHolder(View view, int viewType) { + public TemplateViewHolder(WXRecyclerTemplateList templateList, View view, int viewType) { super(view, viewType); + this.templateList = templateList; } - // TODO -// public CSSLayoutContext getLayoutContext() { -// if(layoutContext == null){ -// layoutContext = new CSSLayoutContext(); -// } -// return layoutContext; -// } -// -// public void setLayoutContext(CSSLayoutContext layoutContext){ -// this.layoutContext = layoutContext; -// } + public int getHolderPosition() { @@ -79,4 +72,8 @@ public class TemplateViewHolder extends ListBaseViewHolder { public WXCell getTemplate() { return template; } + + public WXRecyclerTemplateList getTemplateList() { + return templateList; + } }
