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

Commit 615133cc authored by Edgar Wang's avatar Edgar Wang
Browse files

Fix the scrolling behavior in Settings homepage

- we always scroll to top of homepage first.
- if target position already exist on screen,
  we don't need to scroll.
- if target position doesn't exist on screen,
  scroll to the target position.

Bug: 349696107
Test: manual
Flag: com.android.settings.flags.homepage_revamp
Change-Id: I18c314d19eb38f22f799cb8bf087bf71f4f7d466
parent 5c466c5b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.widget;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
@@ -212,6 +213,14 @@ public class HighlightableTopLevelPreferenceAdapter extends RoundCornerPreferenc
        // Scroll to the top to reset the position.
        mRecyclerView.nestedScrollBy(0, -mRecyclerView.getHeight());

        // get the visible area of the recycler view
        Rect rvRect = new Rect();
        mRecyclerView.getGlobalVisibleRect(rvRect);
        if (Flags.homepageRevamp() && view.getBottom() <= rvRect.height()) {
            // the request position already fully visible in the visible area
            return;
        }

        final int scrollY = view.getTop();
        if (scrollY > 0) {
            mRecyclerView.nestedScrollBy(0, scrollY);