[WEEX-110][android]WXSwipeLayout support nested scroll 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/874147d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/874147d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/874147d8

Branch: refs/heads/master
Commit: 874147d8f28f2ab9a3656a3f4ba5e2df8753800e
Parents: d4c004b
Author: jianbai.gbj <jianbai....@alibaba-inc.com>
Authored: Tue Oct 31 14:05:52 2017 +0800
Committer: jianbai.gbj <jianbai....@alibaba-inc.com>
Committed: Tue Nov 14 11:27:54 2017 +0800

----------------------------------------------------------------------
 .../weex/ui/component/list/WXListComponent.java |  10 +-
 .../list/template/WXRecyclerTemplateList.java   |   5 +
 .../ui/view/refresh/core/WXSwipeLayout.java     | 130 ++++++++++++++-----
 3 files changed, 110 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/874147d8/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 c5ef8b5..507a40c 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
@@ -37,6 +37,7 @@ import com.taobao.weex.ui.component.WXVContainer;
 import com.taobao.weex.ui.view.listview.WXRecyclerView;
 import com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder;
 import com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView;
+import com.taobao.weex.utils.WXUtils;
 
 import java.util.Map;
 
@@ -79,8 +80,13 @@ public class WXListComponent extends 
BasicListComponent<BounceRecyclerView> {
 
   @Override
   protected BounceRecyclerView generateListView(Context context, int 
orientation) {
-
-    return new 
BounceRecyclerView(context,mLayoutType,mColumnCount,mColumnGap,orientation);
+    BounceRecyclerView bounceRecyclerView = new 
BounceRecyclerView(context,mLayoutType,mColumnCount,mColumnGap,orientation);
+    if(bounceRecyclerView.getSwipeLayout()  != null){
+      
if(WXUtils.getBoolean(getDomObject().getAttrs().get("nestedScrollingEnabled"), 
false)) {
+          bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true);
+      }
+    }
+    return  bounceRecyclerView;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/874147d8/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 76bcce0..54e1564 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
@@ -236,6 +236,11 @@ public class WXRecyclerTemplateList extends 
WXVContainer<BounceRecyclerView> imp
         if(itemViewCacheSize != 2) {
             
bounceRecyclerView.getInnerView().setItemViewCacheSize(itemViewCacheSize);
         }
+        if(bounceRecyclerView.getSwipeLayout()  != null){
+            
if(WXUtils.getBoolean(getDomObject().getAttrs().get("nestedScrollingEnabled"), 
false)) {
+                
bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true);
+            }
+        }
         bounceRecyclerView.getInnerView().setHasFixedSize(hasFixedSize);
         bounceRecyclerView.setRecyclerViewBaseAdapter(recyclerViewBaseAdapter);
         bounceRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/874147d8/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java
 
b/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java
index e1ec10b..a69dc0e 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/ui/view/refresh/core/WXSwipeLayout.java
@@ -29,12 +29,15 @@ import android.support.v4.view.NestedScrollingChildHelper;
 import android.support.v4.view.NestedScrollingParent;
 import android.support.v4.view.NestedScrollingParentHelper;
 import android.support.v4.view.ViewCompat;
+import android.support.v4.view.ViewParentCompat;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.util.TypedValue;
 import android.view.Gravity;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewParent;
 import android.widget.AbsListView;
 import android.widget.FrameLayout;
 
@@ -48,6 +51,8 @@ public class WXSwipeLayout extends FrameLayout implements 
NestedScrollingParent,
   private WXOnRefreshListener onRefreshListener;
   private WXOnLoadingListener onLoadingListener;
 
+  private ViewParent mNestedScrollAcceptedParent;
+
   /**
    * On refresh Callback, call on start refresh
    */
@@ -151,7 +156,7 @@ public class WXSwipeLayout extends FrameLayout implements 
NestedScrollingParent,
 
     mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
     mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
-    setNestedScrollingEnabled(true);
+    setNestedScrollingEnabled(false);
 
     if (isInEditMode() && attrs == null) {
       return;
@@ -234,12 +239,32 @@ public class WXSwipeLayout extends FrameLayout implements 
NestedScrollingParent,
 
   @Override
   public boolean startNestedScroll(int axes) {
-    return mNestedScrollingChildHelper.startNestedScroll(axes);
+    boolean result = mNestedScrollingChildHelper.startNestedScroll(axes);
+    if(result){
+       if(mNestedScrollAcceptedParent == null){
+            ViewParent parent  = this.getParent();
+            View child = this;
+            while (parent != null) {
+              if (ViewParentCompat.onStartNestedScroll(parent, child, this, 
axes)){
+                 mNestedScrollAcceptedParent = parent;
+                 break;
+              }
+              if(parent instanceof  View){
+                child = (View) parent;
+              }
+              parent = parent.getParent();
+            }
+       }
+    }
+    return result;
   }
 
   @Override
   public void stopNestedScroll() {
     mNestedScrollingChildHelper.stopNestedScroll();
+    if(mNestedScrollAcceptedParent != null){
+      mNestedScrollAcceptedParent = null;
+    }
   }
 
   @Override
@@ -260,17 +285,7 @@ public class WXSwipeLayout extends FrameLayout implements 
NestedScrollingParent,
             dx, dy, consumed, offsetInWindow);
   }
 
-  @Override
-  public boolean onNestedPreFling(View target, float velocityX,
-                                  float velocityY) {
-    return dispatchNestedPreFling(velocityX, velocityY);
-  }
 
-  @Override
-  public boolean onNestedFling(View target, float velocityX, float velocityY,
-                               boolean consumed) {
-    return dispatchNestedFling(velocityX, velocityY, consumed);
-  }
 
   @Override
   public boolean dispatchNestedFling(float velocityX, float velocityY, boolean 
consumed) {
@@ -284,17 +299,40 @@ public class WXSwipeLayout extends FrameLayout implements 
NestedScrollingParent,
 
   /*********************************** NestedScrollParent 
*************************************/
 
+
+  @Override
+  public boolean onNestedPreFling(View target, float velocityX,
+                                  float velocityY) {
+    if(isNestedScrollingEnabled()) {
+      return dispatchNestedPreFling(velocityX, velocityY);
+    }
+    return  false;
+  }
+
+  @Override
+  public boolean onNestedFling(View target, float velocityX, float velocityY,
+                               boolean consumed) {
+    if(isNestedScrollingEnabled()) {
+      return dispatchNestedFling(velocityX, velocityY, consumed);
+    }
+    return  false;
+  }
+
   @Override
   public boolean onStartNestedScroll(View child, View target, int 
nestedScrollAxes) {
-    return isEnabled()  && !mRefreshing
+    boolean result =  isEnabled()  && !mRefreshing
             && (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
+
+    return  result;
   }
 
   @Override
   public void onNestedScrollAccepted(View child, View target, int axes) {
     mNestedScrollingParentHelper.onNestedScrollAccepted(child, target, axes);
-    startNestedScroll(axes & ViewCompat.SCROLL_AXIS_VERTICAL);
-    mNestedScrollInProgress = true;
+    if(isNestedScrollingEnabled()){
+      startNestedScroll(axes & ViewCompat.SCROLL_AXIS_VERTICAL);
+      mNestedScrollInProgress = true;
+    }
   }
 
 
@@ -307,36 +345,58 @@ public class WXSwipeLayout extends FrameLayout implements 
NestedScrollingParent,
    */
   @Override
   public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {
-    if ((!mPullRefreshEnable && !mPullLoadEnable)) {
-      // Now let our nested parent consume the leftovers
-      final int[] parentConsumed = mParentScrollConsumed;
+    // Now let our nested parent consume the leftovers
+    final int[] parentConsumed = mParentScrollConsumed;
+    if(isNestedScrollingEnabled()){
       if (dispatchNestedPreScroll(dx - consumed[0], dy - consumed[1], 
parentConsumed, null)) {
         consumed[0] += parentConsumed[0];
         consumed[1] += parentConsumed[1];
+        return;
       }
+    }
+    if ((!mPullRefreshEnable && !mPullLoadEnable)) {
       return;
     }
 
-    dy = (int) calculateDistanceY(target, dy);
+    /**
+     * when in nest-scroll, list canChildScrollUp() false,
+     * maybe parent scroll can scroll up
+     * */
+    if(!canChildScrollUp() && isNestedScrollingEnabled()){
+      if(mNestedScrollAcceptedParent != null && mNestedScrollAcceptedParent != 
mTargetView){
+        ViewGroup group = (ViewGroup) mNestedScrollAcceptedParent;
+        if(group.getChildCount() > 0){
+          int count = group.getChildCount();
+          for(int i=0; i<count; i++){
+            View view  = group.getChildAt(i);
+            if(view.getVisibility() != View.GONE && view.getMeasuredHeight() > 
0){
+              if(view.getTop() < 0){
+                return;
+              }else{
+                break;
+              }
+            }
+          }
+        }
+      }
+    }
+
+
+
+    int spinnerDy = (int) calculateDistanceY(target, dy);
 
     if (!isConfirm) {
-      if (dy < 0 && !canChildScrollUp()) {
+      if (spinnerDy < 0 && !canChildScrollUp()) {
         mCurrentAction = PULL_REFRESH;
         isConfirm = true;
-      } else if (dy > 0 && !canChildScrollDown() && (!mRefreshing)) {
+      } else if (spinnerDy > 0 && !canChildScrollDown() && (!mRefreshing)) {
         mCurrentAction = LOAD_MORE;
         isConfirm = true;
       }
     }
 
-    if (moveSpinner(-dy)) {
-       consumed[1] += dy;
-    }
-    // Now let our nested parent consume the leftovers
-    final int[] parentConsumed = mParentScrollConsumed;
-    if (dispatchNestedPreScroll(dx - consumed[0], dy - consumed[1], 
parentConsumed, null)) {
-      consumed[0] += parentConsumed[0];
-      consumed[1] += parentConsumed[1];
+    if (moveSpinner(-spinnerDy)) {
+       consumed[1] += spinnerDy;
     }
   }
 
@@ -354,15 +414,19 @@ public class WXSwipeLayout extends FrameLayout implements 
NestedScrollingParent,
   @Override
   public void onStopNestedScroll(View child) {
     mNestedScrollingParentHelper.onStopNestedScroll(child);
-    mNestedScrollInProgress = true;
-    handlerAction();
-    stopNestedScroll();
+    if(isNestedScrollingEnabled()) {
+      mNestedScrollInProgress = true;
+      handlerAction();
+      stopNestedScroll();
+    }
   }
 
 
   @Override
   public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int 
dxUnconsumed, int dyUnconsumed) {
-     dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, 
mParentOffsetInWindow);
+    if(isNestedScrollingEnabled()) {
+      dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, 
mParentOffsetInWindow);
+    }
   }
 
 

Reply via email to