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

Commit 6d21df2e authored by Rahul Ravikumar's avatar Rahul Ravikumar
Browse files

Added a ScrollView#scrollToDescendant() API.

* Eliminates the need for a reflective call to Landroid/widget/ScrollView;->mChildToScrollTo:Landroid/view/View;

Test: Added CTS tests.
Fixes: b/123769715

Change-Id: If28891cdeda3c13c3dd5d9b4faf697543311590a
parent adafb1b4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -56647,6 +56647,7 @@ package android.widget {
    method public boolean isFillViewport();
    method public boolean isSmoothScrollingEnabled();
    method public boolean pageScroll(int);
    method public void scrollToDescendant(android.view.View);
    method public void setFillViewport(boolean);
    method public void setSmoothScrollingEnabled(boolean);
    method public final void smoothScrollBy(int, int);
+14 −10
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class ScrollView extends FrameLayout {
     * layout is dirty. This prevents the scroll from being wrong if the child has not been
     * laid out before requesting focus.
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123769715)
    private View mChildToScrollTo = null;

    /**
@@ -1382,7 +1382,8 @@ public class ScrollView extends FrameLayout {
     *
     * @param child the View to scroll to
     */
    private void scrollToChild(View child) {
    public void scrollToDescendant(View child) {
        if (!mIsLayoutDirty) {
            child.getDrawingRect(mTempRect);

            /* Offset from child's local coordinates to ScrollView coordinates */
@@ -1393,6 +1394,9 @@ public class ScrollView extends FrameLayout {
            if (scrollDelta != 0) {
                scrollBy(0, scrollDelta);
            }
        } else {
            mChildToScrollTo = child;
        }
    }

    /**
@@ -1486,7 +1490,7 @@ public class ScrollView extends FrameLayout {
    public void requestChildFocus(View child, View focused) {
        if (focused != null && focused.getRevealOnFocusHint()) {
            if (!mIsLayoutDirty) {
                scrollToChild(focused);
                scrollToDescendant(focused);
            } else {
                // The child may not be laid out yet, we can't compute the scroll yet
                mChildToScrollTo = focused;
@@ -1567,7 +1571,7 @@ public class ScrollView extends FrameLayout {
        mIsLayoutDirty = false;
        // Give a child focus if it needs it
        if (mChildToScrollTo != null && isViewDescendantOf(mChildToScrollTo, this)) {
            scrollToChild(mChildToScrollTo);
            scrollToDescendant(mChildToScrollTo);
        }
        mChildToScrollTo = null;