You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/12/26 07:15:32 UTC
incubator-weex git commit: [WEEX-170][android] WXTemplateList width
should use realpx instead of viewport and post add cell archive better
performance close #945
Repository: incubator-weex
Updated Branches:
refs/heads/master 7cd272842 -> e84d927be
[WEEX-170][android] WXTemplateList width should use realpx instead of viewport and post add cell archive better performance
close #945
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/e84d927b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/e84d927b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/e84d927b
Branch: refs/heads/master
Commit: e84d927bee574bc87c2900cfac0bd259079b1496
Parents: 7cd2728
Author: jianbai.gbj <ji...@alibaba-inc.com>
Authored: Thu Dec 14 14:28:54 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Tue Dec 26 15:14:35 2017 +0800
----------------------------------------------------------------------
.../com/taobao/weex/dom/WXCellDomObject.java | 25 ++++++++++------
.../taobao/weex/dom/WXRecyclerDomObject.java | 17 +++++++----
.../weex/ui/component/binding/Statements.java | 13 ++++----
.../list/template/WXRecyclerTemplateList.java | 31 +++++++++++++++-----
4 files changed, 58 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e84d927b/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java
index 649a09d..d8ef325 100644
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java
+++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java
@@ -18,10 +18,12 @@
*/
package com.taobao.weex.dom;
+
import com.taobao.weex.dom.flex.CSSNode;
import com.taobao.weex.dom.flex.MeasureOutput;
import com.taobao.weex.ui.component.WXBasicComponentType;
import com.taobao.weex.utils.WXLogUtils;
+import com.taobao.weex.utils.WXViewUtils;
/**
* Created by zhengshihan on 2017/4/11.
@@ -36,17 +38,19 @@ public class WXCellDomObject extends WXDomObject {
CSSNode parent = node.getParent();
if (parent != null && parent instanceof WXRecyclerDomObject) {
WXRecyclerDomObject parentDom = ((WXRecyclerDomObject) parent);
- parentDom.preCalculateCellWidth();
+ if(!parentDom.hasPreCalculateCellWidth()) {
+ parentDom.preCalculateCellWidth();
+ }
WXDomObject domObject = (WXDomObject) node;
if (WXBasicComponentType.CELL.equals(domObject.getType())
|| WXBasicComponentType.CELL_SLOT.equals(domObject.getType())) {
float w = ((WXRecyclerDomObject) parent).getColumnWidth();
- if(w <= 0 && parentDom.getColumnCount() <= 1){
+ if((w <= 0 || Float.isNaN(w)) && parentDom.getColumnCount() <= 1){
w = parentDom.getAvailableWidth();
- if(w <= 0){
+ if(w <= 0 || Float.isNaN(w)){
w = parentDom.getLayoutWidth();
- if(w <= 0){
- w = parentDom.getViewPortWidth();
+ if(w <= 0 || Float.isNaN(w)){
+ w = WXViewUtils.getRealPxByWidth( parentDom.getViewPortWidth(), parentDom.getViewPortWidth());
}
}
}
@@ -76,12 +80,15 @@ public class WXCellDomObject extends WXDomObject {
recyclerDomObject.preCalculateCellWidth();
}
float w = recyclerDomObject.getColumnWidth();
- if(w <= 0 && recyclerDomObject.getColumnCount() <= 1){
+ if((w <= 0 || Float.isNaN(w)) && recyclerDomObject.getColumnCount() <= 1){
w = recyclerDomObject.getAvailableWidth();
- if(w <= 0){
+ if(w <= 0 || Float.isNaN(w)){
w = recyclerDomObject.getLayoutWidth();
- if(w <= 0){
- w = recyclerDomObject.getViewPortWidth();
+ if(w <= 0 || Float.isNaN(w)){
+ w = recyclerDomObject.getStyleWidth();
+ if(w <= 0 || Float.isNaN(w)){
+ w = WXViewUtils.getRealPxByWidth(recyclerDomObject.getViewPortWidth(), recyclerDomObject.getViewPortWidth());
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e84d927b/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
index 805ef8e..5fe245b 100644
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
+++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
@@ -109,17 +109,22 @@ public class WXRecyclerDomObject extends WXDomObject{
@Override
public float getStyleWidth() {
- float width = getLayoutWidth();
+ float width = super.getStyleWidth();
if (Float.isNaN(width) || width <= 0){
- if(getParent() != null){
- width = getParent().getLayoutWidth();
- }
+ width = super.getLayoutWidth();
if (Float.isNaN(width) || width <= 0){
- width = super.getStyleWidth();
+ if(getStyles().containsKey(Constants.Name.WIDTH)) {
+ width = WXViewUtils.getRealPxByWidth(getStyles().containsKey(Constants.Name.WIDTH) ? getStyles().getWidth(getViewPortWidth()) : getStyles().getDefaultWidth(), getViewPortWidth());
+ }
+ if (Float.isNaN(width) || width <= 0){
+ if(getParent() != null){
+ width = getParent().getLayoutWidth();
+ }
+ }
}
}
if (Float.isNaN(width) || width <= 0){
- width = getViewPortWidth();
+ width = WXViewUtils.getRealPxByWidth(getViewPortWidth(), getViewPortWidth());
}
return width;
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e84d927b/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 548a1a0..2ed3fae 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
@@ -341,14 +341,17 @@ public class Statements {
while (iterator.hasNext()){
Map.Entry<String, Object> entry = iterator.next();
String key = entry.getKey();
- if(entry.getValue() == null){
- if(attr.get(key) == null){
+ Object value = entry.getValue();
+ Object oldValue = attr.get(key);
+ if(value == null){
+ if(oldValue == null){
iterator.remove();
continue;
}
- }
- if(entry.getValue().equals(attr.get(key))){
- iterator.remove();
+ }else{
+ if(value.equals(oldValue)){
+ iterator.remove();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e84d927b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java
index ad069bb..51a4874 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/list/template/WXRecyclerTemplateList.java
@@ -44,6 +44,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKInstance;
+import com.taobao.weex.WXSDKManager;
import com.taobao.weex.annotation.Component;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.Constants;
@@ -177,6 +178,7 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp
private ArrayStack bindIngStackContext = new ArrayStack();
private Map bindIngMapContext = new HashMap();
+
public WXRecyclerTemplateList(WXSDKInstance instance, WXDomObject node, WXVContainer parent) {
super(instance, node, parent);
initRecyclerTemplateList(instance, node, parent);
@@ -204,15 +206,28 @@ public class WXRecyclerTemplateList extends WXVContainer<BounceRecyclerView> imp
listData = array;
}
}
- long start = System.currentTimeMillis();
- if(mDomObject != null && mDomObject.getCellList() != null){
- for(int i=0; i<mDomObject.getCellList().size(); i++){
- addChild(DomTreeBuilder.buildTree(mDomObject.getCellList().get(i), this));
+ /**
+ * we have separate cell with list, post add cell in dom thread ensure
+ * list has layout and can archive better user experience and better load time,
+ * which reduce waste cell layout when list layout changes.
+ * */
+ WXSDKManager.getInstance().getWXDomManager().post(new Runnable() {
+ @Override
+ public void run() {
+ if(isDestoryed()){
+ return;
+ }
+ long start = System.currentTimeMillis();
+ if(mDomObject != null && mDomObject.getCellList() != null){
+ for(int i=0; i<mDomObject.getCellList().size(); i++){
+ addChild(DomTreeBuilder.buildTree(mDomObject.getCellList().get(i), WXRecyclerTemplateList.this));
+ }
+ }
+ if(WXEnvironment.isApkDebugable()){
+ WXLogUtils.d(TAG, "TemplateList BuildDomTree Used " + (System.currentTimeMillis() - start));
+ }
}
- }
- if(WXEnvironment.isApkDebugable()){
- WXLogUtils.d(TAG, "TemplateList BuildDomTree Used " + (System.currentTimeMillis() - start));
- }
+ });
}
@Override