You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by zs...@apache.org on 2017/08/01 02:54:38 UTC

[11/50] [abbrv] incubator-weex git commit: * [android] fix illegal value in scroll event for list

* [android] fix illegal value in scroll event for list


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/831cb26d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/831cb26d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/831cb26d

Branch: refs/heads/dev
Commit: 831cb26d33e3faa2047192e36fff9d67631569d2
Parents: da56268
Author: misakuo <mi...@apache.org>
Authored: Thu Jul 20 15:26:03 2017 +0800
Committer: misakuo <mi...@apache.org>
Committed: Thu Jul 20 15:26:03 2017 +0800

----------------------------------------------------------------------
 .../ui/component/list/BasicListComponent.java   | 66 +++++++++-----------
 .../taobao/weex/ui/component/list/WXCell.java   | 10 ---
 2 files changed, 30 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/831cb26d/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 f3f6ac6..cdff266 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
@@ -113,7 +113,6 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
 
   private int mOffsetAccuracy = 10;
   private Point mLastReport = new Point(-1, -1);
-  private boolean mStable = false;
 
   private RecyclerView.ItemAnimator mItemAnimator;
 
@@ -133,16 +132,6 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
   private static final boolean DEFAULT_EXCLUDED = false;
 
   private static final String DRAG_ANCHOR = "dragAnchor";
-  private float mContentHeight = 0;
-
-  public void recalculateSize() {
-    float height = 0;
-    for(int i=0, c = getChildCount(); i<=c-1 ; i++){
-      height += getChild(i).getLayoutHeight();
-    }
-    mContentHeight = height;
-    fireScrollEvent(0,0);
-  }
 
   /**
    * gesture type which can trigger drag&drop
@@ -191,12 +180,6 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
     mTriggerType = getTriggerType(getDomObject());
   }
 
-  @Override
-  protected void onFinishLayout() {
-    super.onFinishLayout();
-    recalculateSize();
-  }
-
   /**
    * Measure the size of the recyclerView.
    *
@@ -420,9 +403,6 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
         int accuracy = WXUtils.getInteger(param, 10);
         setOffsetAccuracy(accuracy);
         return true;
-      case Constants.Name.STABLE:
-        this.mStable = WXUtils.getBoolean(param, false);
-        return true;
       case Constants.Name.DRAGGABLE:
         boolean draggable = WXUtils.getBoolean(param,false);
         setDraggable(draggable);
@@ -1255,36 +1235,47 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
     if (Constants.Event.SCROLL.equals(type) && getHostView() != null && getHostView().getInnerView() != null) {
       WXRecyclerView innerView = getHostView().getInnerView();
       innerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
-        private int totalDy = 0;
+        private int offsetXCorrection, offsetYCorrection;
+        private boolean mFirstEvent = true;
 
         @Override
         public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
           super.onScrolled(recyclerView, dx, dy);
+//          WXLogUtils.e("SCROLL", dx + ", " + dy + ", " + recyclerView.computeHorizontalScrollRange()
+//          + ", " + recyclerView.computeVerticalScrollRange()
+//          + ", " + recyclerView.computeHorizontalScrollOffset()
+//          + ", " + recyclerView.computeVerticalScrollOffset());
+
           int offsetX = recyclerView.computeHorizontalScrollOffset();
-          int offsetY = 0;
-          if (mStable) {
-            totalDy -= dy;
-            offsetY = totalDy;
+          int offsetY = recyclerView.computeVerticalScrollOffset();
+
+          if (dx == 0 && dy == 0) {
+            offsetXCorrection = offsetX;
+            offsetYCorrection = offsetY;
+            offsetX = 0;
+            offsetY = 0;
           } else {
-            offsetY = recyclerView.computeVerticalScrollOffset();
+            offsetX = offsetX - offsetXCorrection;
+            offsetY = offsetY - offsetYCorrection;
+          }
+
+          if (mFirstEvent) {
+            //skip first event
+            mFirstEvent = false;
+            return;
           }
 
           if (shouldReport(offsetX, offsetY)) {
-            fireScrollEvent(offsetX, offsetY);
+            fireScrollEvent(recyclerView, offsetX, offsetY);
           }
         }
       });
     }
   }
 
-  private void fireScrollEvent(int offsetX, int offsetY){
-    ListComponentView view = getHostView();
-    if(view == null){
-      return;
-    }
-    WXRecyclerView innerView = view.getInnerView();
-    int contentWidth = innerView.getMeasuredWidth() + innerView.computeHorizontalScrollRange();
-    int contentHeight = (int)mContentHeight;
+  private void fireScrollEvent(RecyclerView recyclerView, int offsetX, int offsetY) {
+    int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange();
+    int contentHeight = recyclerView.computeVerticalScrollRange();
 
     Map<String, Object> event = new HashMap<>(2);
     Map<String, Object> contentSize = new HashMap<>(2);
@@ -1308,7 +1299,10 @@ public abstract class BasicListComponent<T extends ViewGroup & ListComponentView
       return true;
     }
 
-    if (Math.abs(mLastReport.x - offsetX) >= mOffsetAccuracy || Math.abs(mLastReport.y - offsetY) >= mOffsetAccuracy) {
+    int gapX = Math.abs(mLastReport.x - offsetX);
+    int gapY = Math.abs(mLastReport.y - offsetY);
+
+    if (gapX >= mOffsetAccuracy || gapY >= mOffsetAccuracy) {
       mLastReport.x = offsetX;
       mLastReport.y = offsetY;
       return true;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/831cb26d/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 172f19b..9a5e468 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
@@ -27,7 +27,6 @@ import android.widget.FrameLayout;
 import com.taobao.weex.WXSDKInstance;
 import com.taobao.weex.annotation.Component;
 import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.dom.flex.CSSLayout;
 import com.taobao.weex.ui.component.WXVContainer;
 import com.taobao.weex.ui.view.WXFrameLayout;
 
@@ -83,15 +82,6 @@ public class WXCell extends WXVContainer<WXFrameLayout> {
         }
     }
 
-    @Override
-    protected void onFinishLayout() {
-        super.onFinishLayout();
-        WXVContainer container = getParent();
-        if(container != null && container instanceof BasicListComponent){
-            ((BasicListComponent)container).recalculateSize();
-        }
-    }
-
     public int getLocationFromStart(){
         return mLastLocationY;
     }