From d568294c1a587fd712b41f072d6e1a521fe09a72 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Mon, 8 Apr 2019 09:57:07 -0400 Subject: [PATCH] Sharesheet - Fix scroll behavior moving past bounds ResolverDrawerLayout is tracking fractions of pixels, but just drops these fractions when offsetting the child views. When scrolling up and down continuously, this can lead to the view scrolling past the window bounds. Do not discard these fractions. Track the remainders and add them in when the sum to >= 1px. Bug: 129979914 Test: Manual scrolling test Change-Id: I0e8ea04baca341c6b6e0573e086f3f2f8c2b39b5 --- .../internal/widget/ResolverDrawerLayout.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/java/com/android/internal/widget/ResolverDrawerLayout.java b/core/java/com/android/internal/widget/ResolverDrawerLayout.java index 329c6b395bba..66bbe22c9969 100644 --- a/core/java/com/android/internal/widget/ResolverDrawerLayout.java +++ b/core/java/com/android/internal/widget/ResolverDrawerLayout.java @@ -73,6 +73,11 @@ public class ResolverDrawerLayout extends ViewGroup { */ private float mCollapseOffset; + /** + * Track fractions of pixels from drag calculations. Without this, the view offsets get + * out of sync due to frequently dropping fractions of a pixel from '(int) dy' casts. + */ + private float mDragRemainder = 0.0f; private int mCollapsibleHeight; private int mUncollapsibleHeight; private int mAlwaysShowHeight; @@ -485,6 +490,16 @@ public class ResolverDrawerLayout extends ViewGroup { mCollapsibleHeight + mUncollapsibleHeight)); if (newPos != mCollapseOffset) { dy = newPos - mCollapseOffset; + + mDragRemainder += dy - (int) dy; + if (mDragRemainder >= 1.0f) { + mDragRemainder -= 1.0f; + dy += 1.0f; + } else if (mDragRemainder <= -1.0f) { + mDragRemainder += 1.0f; + dy -= 1.0f; + } + final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i);