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
This commit is contained in:
Jon Miranda
2018-04-23 15:11:00 -07:00
parent 6aef85c417
commit 5918662f32
@@ -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());
}