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

Commit e675a8e6 authored by Steven Ng's avatar Steven Ng
Browse files

Fix full widgets picker fast scroll offset issue

Even though there is no change in fast scroller offset, the recycler view
scroll Y may still be updated. Let's also notify a scroll change if
the recycler view scroll has changed when updating the fast scroller thumb
offset.

Test: In the full widgets picker, scroll up and down with the fast
      scroller. Then, scroll up and down in the recycler view. The top
      section is scrolled together with the recycler view smoothly.
Bug: 183721076
Change-Id: I009fc7e27c8a20505a60502405ebbf695b5a37f2
parent 1282050f
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ public class RecyclerViewFastScroller extends View {
    // prevent jumping, this offset is applied as the user scrolls.
    protected int mTouchOffsetY;
    protected int mThumbOffsetY;
    protected int mRvOffsetY;

    // Fast scroller popup
    private TextView mPopupView;
@@ -186,14 +187,18 @@ public class RecyclerViewFastScroller extends View {

    public void setThumbOffsetY(int y) {
        if (mThumbOffsetY == y) {
            int rvCurrentOffsetY = mRv.getCurrentScrollY();
            if (mRvOffsetY != rvCurrentOffsetY) {
                mRvOffsetY = mRv.getCurrentScrollY();
                notifyScrollChanged();
            }
            return;
        }
        updatePopupY(y);
        mThumbOffsetY = y;
        invalidate();
        if (mOnFastScrollChangeListener != null) {
            mOnFastScrollChangeListener.onThumbOffsetYChanged(mThumbOffsetY);
        }
        mRvOffsetY = mRv.getCurrentScrollY();
        notifyScrollChanged();
    }

    public int getThumbOffsetY() {
@@ -422,13 +427,17 @@ public class RecyclerViewFastScroller extends View {
        mOnFastScrollChangeListener = onFastScrollChangeListener;
    }

    private void notifyScrollChanged() {
        if (mOnFastScrollChangeListener != null) {
            mOnFastScrollChangeListener.onScrollChanged();
        }
    }

    /**
     * A callback that is invoked when there is a scroll change in {@link RecyclerViewFastScroller}.
     */
    public interface OnFastScrollChangeListener {
        /**
         * Called when the thumb offset vertical position, in pixels, has changed to {@code y}.
         */
        void onThumbOffsetYChanged(int y);
        /** Called when the recycler view scroll has changed. */
        void onScrollChanged();
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ final class SearchAndRecommendationsScrollController implements
     * views (e.g. recycler views, tabs) upon scrolling.
     */
    @Override
    public void onThumbOffsetYChanged(int unused) {
    public void onScrollChanged() {
        // Always use the recycler view offset because fast scroller offset has a different scale.
        int recyclerViewYOffset = mCurrentRecyclerView.getCurrentScrollY();
        if (recyclerViewYOffset < 0) return;