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

Commit 43943d8b authored by Yorke Lee's avatar Yorke Lee
Browse files

Fix nested scrolling bugs in AbsListView

* rawDeltaY should be offset by mMotionCorrection when passing it
to dispatchNestedPreScroll
* mScrollOffset should offset the next motion event, not the current
one

Bug: 14572732

Change-Id: Ib98f27d608b91706af4537e1cf9ad42adce121ea
parent 80914669
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -3305,18 +3305,22 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

    private void scrollIfNeeded(int y, MotionEvent vtev) {
        int rawDeltaY = y - mMotionY;
        int scrollOffsetCorrection = 0;
        int scrollConsumedCorrection = 0;
        if (mLastY == Integer.MIN_VALUE) {
            rawDeltaY -= mMotionCorrection;
        }
        if (dispatchNestedPreScroll(0, rawDeltaY, mScrollConsumed, mScrollOffset)) {
            rawDeltaY -= mScrollConsumed[1];
            mMotionCorrection -= mScrollOffset[1];
            if (mLastY != Integer.MIN_VALUE) {
                mLastY -= mScrollOffset[1] + mScrollConsumed[1];
            }
            scrollOffsetCorrection -= mScrollOffset[1];
            scrollConsumedCorrection -= mScrollConsumed[1];
            if (vtev != null) {
                vtev.offsetLocation(0, mScrollOffset[1]);
            }
        }
        final int deltaY = rawDeltaY - mMotionCorrection;
        int incrementalDeltaY = mLastY != Integer.MIN_VALUE ? y - mLastY : deltaY;
        final int deltaY = rawDeltaY;
        int incrementalDeltaY =
                mLastY != Integer.MIN_VALUE ? y - mLastY - scrollConsumedCorrection : deltaY;
        int lastYCorrection = 0;

        if (mTouchMode == TOUCH_MODE_SCROLL) {
@@ -3378,7 +3382,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                                (motionViewRealTop - motionViewPrevTop);
                        if (dispatchNestedScroll(0, overscroll - incrementalDeltaY, 0, overscroll,
                                mScrollOffset)) {
                            mMotionCorrection -= mScrollOffset[1];
                            lastYCorrection -= mScrollOffset[1];
                            if (vtev != null) {
                                vtev.offsetLocation(0, mScrollOffset[1]);
@@ -3415,9 +3418,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                            }
                        }
                    }
                    mMotionY = y;
                    mMotionY = y + scrollOffsetCorrection;
                }
                mLastY = y + lastYCorrection;
                mLastY = y + lastYCorrection + scrollOffsetCorrection;
            }
        } else if (mTouchMode == TOUCH_MODE_OVERSCROLL) {
            if (y != mLastY) {