You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2018/05/30 09:17:31 UTC

incubator-weex git commit: [WEEX-416] Add Pull-Refresh Offset Changed Listener

Repository: incubator-weex
Updated Branches:
  refs/heads/master cb9bcb897 -> 2e654f6ae


[WEEX-416] Add Pull-Refresh Offset Changed Listener


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

Branch: refs/heads/master
Commit: 2e654f6ae7edbd711a47c4d1ff9ca864fd89bc95
Parents: cb9bcb8
Author: chuyi <ji...@alibaba-inc.com>
Authored: Wed May 30 10:03:15 2018 +0800
Committer: YorkShen <sh...@gmail.com>
Committed: Wed May 30 17:17:17 2018 +0800

----------------------------------------------------------------------
 .../ui/view/refresh/core/WXSwipeLayout.java     | 34 ++++++++++++++++++++
 1 file changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2e654f6a/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 7e252d5..e6818e1 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
@@ -24,6 +24,7 @@ import android.annotation.TargetApi;
 import android.content.Context;
 import android.graphics.Color;
 import android.os.Build;
+import android.support.annotation.Nullable;
 import android.support.v4.view.NestedScrollingChild;
 import android.support.v4.view.NestedScrollingChildHelper;
 import android.support.v4.view.NestedScrollingParent;
@@ -41,6 +42,9 @@ import android.view.ViewParent;
 import android.widget.AbsListView;
 import android.widget.FrameLayout;
 
+import java.util.LinkedList;
+import java.util.List;
+
 public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent, NestedScrollingChild {
 
   private NestedScrollingParentHelper mNestedScrollingParentHelper;
@@ -53,6 +57,12 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent,
 
   private ViewParent mNestedScrollAcceptedParent;
 
+  private final List<OnRefreshOffsetChangedListener> mRefreshOffsetChangedListeners = new LinkedList<>();
+
+  public interface OnRefreshOffsetChangedListener {
+    void onOffsetChanged(int verticalOffset);
+  }
+
   /**
    * On refresh Callback, call on start refresh
    */
@@ -479,6 +489,7 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent,
       }
       headerView.setLayoutParams(lp);
       onRefreshListener.onPullingDown(distanceY, lp.height, refreshViewFlowHeight);
+      notifyOnRefreshOffsetChangedListener(lp.height);
       headerView.setProgressRotation(lp.height / refreshViewFlowHeight);
       moveTargetView(lp.height);
       return true;
@@ -557,6 +568,7 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent,
       public void onAnimationUpdate(ValueAnimator animation) {
         LayoutParams lp = (LayoutParams) headerView.getLayoutParams();
         lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
+        notifyOnRefreshOffsetChangedListener(lp.height);
         headerView.setLayoutParams(lp);
         moveTargetView(lp.height);
       }
@@ -588,6 +600,7 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent,
       public void onAnimationUpdate(ValueAnimator animation) {
         LayoutParams lp = (LayoutParams) headerView.getLayoutParams();
         lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
+        notifyOnRefreshOffsetChangedListener(lp.height);
         headerView.setLayoutParams(lp);
         moveTargetView(lp.height);
       }
@@ -738,6 +751,27 @@ public class WXSwipeLayout extends FrameLayout implements NestedScrollingParent,
     this.onRefreshListener = onRefreshListener;
   }
 
+  @SuppressWarnings("unused")
+  public void addOnRefreshOffsetChangedListener(@Nullable OnRefreshOffsetChangedListener listener) {
+    if(listener != null && !mRefreshOffsetChangedListeners.contains(listener)) {
+      mRefreshOffsetChangedListeners.add(listener);
+    }
+  }
+
+  @SuppressWarnings("unused")
+  public boolean removeOnRefreshOffsetChangedListener(@Nullable OnRefreshOffsetChangedListener listener) {
+    if(listener != null) {
+      return mRefreshOffsetChangedListeners.remove(listener);
+    }
+    return false;
+  }
+
+  private void notifyOnRefreshOffsetChangedListener(int verticalOffset) {
+    for(OnRefreshOffsetChangedListener listener : mRefreshOffsetChangedListeners) {
+      listener.onOffsetChanged(verticalOffset);
+    }
+  }
+
   /**
    * Callback on refresh finish
    */