Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc9047c5 authored by Zhen Zhang's avatar Zhen Zhang
Browse files

Fix Sharesheet nest scrolling issue introduced by using RecyclerView

ResolverDrawerLayout did not recognize RecyclerView as a nested
scrollable child. This is causing scrolling on areas other than
RecyclerView in Sharesheet won't trigger scrolling of RecyclerView.
Modified ResolverDrawerLayout to recognize RecyclerView and trigger
scrolling back if RecyclerView has been scrolled.

Bug: 150772409
Test: Built and flashed to crosshatch, dragging the header will first
scroll sharesheet to the top.

Change-Id: I4a0fee09d02ed2193155c4cbb18550df9071cd2e
parent 55318a34
Loading
Loading
Loading
Loading
+29 −12
Original line number Diff line number Diff line
@@ -121,7 +121,8 @@ public class ResolverDrawerLayout extends ViewGroup {

    private final Rect mTempRect = new Rect();

    private AbsListView mNestedScrollingChild;
    private AbsListView mNestedListChild;
    private RecyclerView mNestedRecyclerChild;

    private final ViewTreeObserver.OnTouchModeChangeListener mTouchModeChangeListener =
            new ViewTreeObserver.OnTouchModeChangeListener() {
@@ -347,11 +348,20 @@ public class ResolverDrawerLayout extends ViewGroup {
        return mIsDragging || mOpenOnClick;
    }

    private boolean isNestedChildScrolled() {
        return mNestedScrollingChild != null
                && mNestedScrollingChild.getChildCount() > 0
                && (mNestedScrollingChild.getFirstVisiblePosition() > 0
                        || mNestedScrollingChild.getChildAt(0).getTop() < 0);
    private boolean isNestedListChildScrolled() {
        return  mNestedListChild != null
                && mNestedListChild.getChildCount() > 0
                && (mNestedListChild.getFirstVisiblePosition() > 0
                        || mNestedListChild.getChildAt(0).getTop() < 0);
    }

    private boolean isNestedRecyclerChildScrolled() {
        if (mNestedRecyclerChild != null && mNestedRecyclerChild.getChildCount() > 0) {
            final RecyclerView.ViewHolder vh =
                    mNestedRecyclerChild.findViewHolderForAdapterPosition(0);
            return vh == null || vh.itemView.getTop() < 0;
        }
        return false;
    }

    @Override
@@ -396,8 +406,10 @@ public class ResolverDrawerLayout extends ViewGroup {
                }
                if (mIsDragging) {
                    final float dy = y - mLastTouchY;
                    if (dy > 0 && isNestedChildScrolled()) {
                        mNestedScrollingChild.smoothScrollBy((int) -dy, 0);
                    if (dy > 0 && isNestedListChildScrolled()) {
                        mNestedListChild.smoothScrollBy((int) -dy, 0);
                    } else if (dy > 0 && isNestedRecyclerChildScrolled()) {
                        mNestedRecyclerChild.scrollBy(0, (int) -dy);
                    } else {
                        performDrag(dy);
                    }
@@ -452,8 +464,10 @@ public class ResolverDrawerLayout extends ViewGroup {
                            smoothScrollTo(mCollapsibleHeight + mUncollapsibleHeight, yvel);
                            mDismissOnScrollerFinished = true;
                        } else {
                            if (isNestedChildScrolled()) {
                                mNestedScrollingChild.smoothScrollToPosition(0);
                            if (isNestedListChildScrolled()) {
                                mNestedListChild.smoothScrollToPosition(0);
                            } else if (isNestedRecyclerChildScrolled()) {
                                mNestedRecyclerChild.smoothScrollToPosition(0);
                            }
                            smoothScrollTo(yvel < 0 ? 0 : mCollapsibleHeight, yvel);
                        }
@@ -729,8 +743,11 @@ public class ResolverDrawerLayout extends ViewGroup {
    @Override
    public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
        if ((nestedScrollAxes & View.SCROLL_AXIS_VERTICAL) != 0) {
            if (child instanceof AbsListView) {
                mNestedScrollingChild = (AbsListView) child;
            if (target instanceof AbsListView) {
                mNestedListChild = (AbsListView) target;
            }
            if (target instanceof RecyclerView) {
                mNestedRecyclerChild = (RecyclerView) target;
            }
            return true;
        }