You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by mi...@apache.org on 2017/08/18 06:50:38 UTC
[2/2] incubator-weex git commit: * [android] compute content size &
content offset based on layout result
* [android] compute content size & content offset based on layout result
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/e22f02a8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/e22f02a8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/e22f02a8
Branch: refs/heads/0.16-dev
Commit: e22f02a8cd3a4183af919b7296e25ffd3cb71295
Parents: cfc1412
Author: misakuo <mi...@apache.org>
Authored: Fri Aug 18 14:46:49 2017 +0800
Committer: misakuo <mi...@apache.org>
Committed: Fri Aug 18 14:46:49 2017 +0800
----------------------------------------------------------------------
.../taobao/weex/ui/component/WXComponent.java | 14 ++++-
.../ui/component/list/BasicListComponent.java | 54 +++++++++++++++++++-
2 files changed, 65 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e22f02a8/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 c9eaa7b..dd7e470 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
@@ -514,11 +514,21 @@ public abstract class WXComponent<T extends View> implements IWXObject, IWXActi
}
public float getLayoutWidth(){
- return mDomObj == null ? 0 : mDomObj.getLayoutWidth();
+ float w = 0f;
+ if (mDomObj != null) {
+ w = mDomObj.getLayoutWidth();
+ w = Float.isNaN(w) ? 0f : w;
+ }
+ return w;
}
public float getLayoutHeight(){
- return mDomObj == null ? 0 : mDomObj.getLayoutHeight();
+ float h = 0f;
+ if (mDomObj != null) {
+ h = mDomObj.getLayoutHeight();
+ h = Float.isNaN(h) ? 0f : h;
+ }
+ return h;
}
public void setPadding(Spacing padding, Spacing border) {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e22f02a8/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 2a6c960..3c8be1c 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
@@ -1301,8 +1301,9 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
}
private void fireScrollEvent(RecyclerView recyclerView, int offsetX, int offsetY) {
+ offsetY = calcContentOffset(recyclerView);
int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange();
- int contentHeight = recyclerView.computeVerticalScrollRange();
+ int contentHeight = calcContentSize();
Map<String, Object> event = new HashMap<>(2);
Map<String, Object> contentSize = new HashMap<>(2);
@@ -1337,4 +1338,55 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
return false;
}
+
+ private int calcContentSize() {
+ int totalHeight = 0;
+ for (int i = 0; i < getChildCount(); i++) {
+ WXComponent child = getChild(i);
+ if (child != null) {
+ totalHeight += child.getLayoutHeight();
+ }
+ }
+ return totalHeight;
+ }
+
+ private int calcContentOffset(RecyclerView recyclerView) {
+ RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
+ if (layoutManager instanceof LinearLayoutManager) {
+ int firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
+ View firstVisibleView = layoutManager.findViewByPosition(firstVisibleItemPosition);
+ int offset = 0;
+ for (int i=0;i<firstVisibleItemPosition;i++) {
+ WXComponent child = getChild(i);
+ if (child != null) {
+ offset -= child.getLayoutHeight();
+ }
+ }
+
+ if (layoutManager instanceof GridLayoutManager) {
+ int spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
+ offset = offset / spanCount;
+ }
+
+ offset += firstVisibleView.getTop();
+ return offset;
+ } else if (layoutManager instanceof StaggeredGridLayoutManager) {
+ int spanCount = ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
+ int firstVisibleItemPosition = ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(null)[0];
+ View firstVisibleView = layoutManager.findViewByPosition(firstVisibleItemPosition);
+
+ int offset = 0;
+ for (int i=0;i<firstVisibleItemPosition;i++) {
+ WXComponent child = getChild(i);
+ if (child != null) {
+ offset -= child.getLayoutHeight();
+ }
+ }
+
+ offset = offset / spanCount;
+ offset += firstVisibleView.getTop();
+ return offset;
+ }
+ return -1;
+ }
}