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

Commit 5918662f authored by Jon Miranda's avatar Jon Miranda
Browse files

Fix bug where scroll position jumps when in overscroll.

When bouncing between top/bottom overscroll, mDistance calculation
allows it to increase without bounds. This solution resets
mDistance to 0 for the edge that is not being overscrolled.

Bug: 78364220
Change-Id: I8371b3aee37e82d40aaa6adc2473a87f2b69931c
parent 6aef85c4
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.EdgeEffectFactory;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.EdgeEffect;
@@ -58,6 +57,7 @@ public class SpringRelativeLayout extends RelativeLayout {
    private final SpringAnimation mSpring;

    private float mDampedScrollShift = 0;
    private SpringEdgeEffect mActiveEdge;

    public SpringRelativeLayout(Context context) {
        this(context, null);
@@ -90,6 +90,13 @@ public class SpringRelativeLayout extends RelativeLayout {
        return super.drawChild(canvas, child, drawingTime);
    }

    private void setActiveEdge(SpringEdgeEffect edge) {
        if (mActiveEdge != edge && mActiveEdge != null) {
            mActiveEdge.mDistance = 0;
        }
        mActiveEdge = edge;
    }

    private void setDampedScrollShift(float shift) {
        if (shift != mDampedScrollShift) {
            mDampedScrollShift = shift;
@@ -144,6 +151,7 @@ public class SpringRelativeLayout extends RelativeLayout {

        @Override
        public void onPull(float deltaDistance, float displacement) {
            setActiveEdge(this);
            mDistance += deltaDistance * (mVelocityMultiplier / 3f);
            setDampedScrollShift(mDistance * getHeight());
        }