From 661e0a03c921925c5e66fdcd23fbb70a209c7850 Mon Sep 17 00:00:00 2001 From: "jianbai.gbj" Date: Thu, 19 Oct 2017 17:57:54 +0800 Subject: [PATCH] when touch use scroll handler, when none touch use nonstop --- .../weex/ui/view/listview/WXRecyclerView.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/listview/WXRecyclerView.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/listview/WXRecyclerView.java index 20be140d46..b2a1793f34 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/view/listview/WXRecyclerView.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/listview/WXRecyclerView.java @@ -42,6 +42,8 @@ public class WXRecyclerView extends RecyclerView implements WXGestureObservable public static final int TYPE_STAGGERED_GRID_LAYOUT = 3; private WXGesture mGesture; private boolean scrollable = true; + private boolean hasTouch = false; + public WXRecyclerView(Context context) { super(context); @@ -91,6 +93,7 @@ public boolean onTouchEvent(MotionEvent event) { if(!scrollable) { return true; } + hasTouch = true; boolean result = super.onTouchEvent(event); if (mGesture != null) { result |= mGesture.onTouch(this, event); @@ -110,26 +113,31 @@ public void scrollTo(boolean smooth, int position, final int offset, final int } //Any else? } else { + smoothScrollToPosition(position); if (offset != 0) { setOnSmoothScrollEndListener(new ExtendedLinearLayoutManager.OnSmoothScrollEndListener() { @Override public void onStop() { - if (orientation == Constants.Orientation.VERTICAL) { - smoothScrollBy(0, offset); - } else { - smoothScrollBy(offset, 0); - } + post(new Runnable() { + @Override + public void run() { + if (orientation == Constants.Orientation.VERTICAL) { + smoothScrollBy(0, offset); + } else { + smoothScrollBy(offset, 0); + } + } + }); } }); } - smoothScrollToPosition(position); } } public void setOnSmoothScrollEndListener(final ExtendedLinearLayoutManager.OnSmoothScrollEndListener onSmoothScrollEndListener){ - if(getLayoutManager() instanceof ExtendedLinearLayoutManager){ + if(getLayoutManager() instanceof ExtendedLinearLayoutManager && !hasTouch){ ExtendedLinearLayoutManager extendedLinearLayoutManager = (ExtendedLinearLayoutManager)getLayoutManager(); - extendedLinearLayoutManager.setOnScrollEndListener(onSmoothScrollEndListener); + extendedLinearLayoutManager.setOnScrollEndListener(onSmoothScrollEndListener); }else{ addOnScrollListener(new RecyclerView.OnScrollListener() { @Override