diff options
| author | 2019-12-26 15:52:33 -0800 | |
|---|---|---|
| committer | 2020-01-02 10:11:47 -0800 | |
| commit | a7cb697874b9afc8c8323d6325df52f24f997e9d (patch) | |
| tree | 871dabd04fffe8d843b69ac0e0a4adb1587782da | |
| parent | 8e9583502a1344b1f8e8dc3ea1beb2337de9145b (diff) | |
Don't let RecyclerView consume fling action when there is no further space.
Before dispatch nested fling, check if there is any further space available
in the requested direction. If yes, set consumed to true; otherwise, false.
This can help list area in sharesheet responds to fling action to collapse.
Bug: 145998887
Test: manually tests. Fling down list area
will collapse sharesheet when list area reach its top edge; otherwise,
the list area itself will fling.
Change-Id: I060a1a91d6bdb0f3d6d0f825b065449223593bfc
| -rw-r--r-- | core/java/com/android/internal/widget/RecyclerView.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/core/java/com/android/internal/widget/RecyclerView.java b/core/java/com/android/internal/widget/RecyclerView.java index b66a7b44f05d..0f0ddbb68a1d 100644 --- a/core/java/com/android/internal/widget/RecyclerView.java +++ b/core/java/com/android/internal/widget/RecyclerView.java @@ -2011,13 +2011,27 @@ public class RecyclerView extends ViewGroup implements ScrollingView, NestedScro } if (!dispatchNestedPreFling(velocityX, velocityY)) { - final boolean canScroll = canScrollHorizontal || canScrollVertical; - dispatchNestedFling(velocityX, velocityY, canScroll); + final View firstChild = mLayout.getChildAt(0); + final View lastChild = mLayout.getChildAt(mLayout.getChildCount() - 1); + boolean consumed = false; + if (velocityY < 0) { + consumed = getChildAdapterPosition(firstChild) > 0 + || firstChild.getTop() < getPaddingTop(); + } + + if (velocityY > 0) { + consumed = getChildAdapterPosition(lastChild) < mAdapter.getItemCount() - 1 + || lastChild.getBottom() > getHeight() - getPaddingBottom(); + } + + dispatchNestedFling(velocityX, velocityY, consumed); if (mOnFlingListener != null && mOnFlingListener.onFling(velocityX, velocityY)) { return true; } + final boolean canScroll = canScrollHorizontal || canScrollVertical; + if (canScroll) { velocityX = Math.max(-mMaxFlingVelocity, Math.min(velocityX, mMaxFlingVelocity)); velocityY = Math.max(-mMaxFlingVelocity, Math.min(velocityY, mMaxFlingVelocity)); |