Merge "Move ScrollView scroll capture to the center" into sc-dev am: 07056eaa46

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14752211

Change-Id: I3be83dca44dc2ae12fbce25a3106fb9aa3b5b14c
This commit is contained in:
Matt Casey
2021-06-03 06:16:24 +00:00
committed by Automerger Merge Worker
2 changed files with 18 additions and 5 deletions

View File

@@ -125,10 +125,19 @@ public class ScrollViewCaptureHelper implements ScrollCaptureViewHelper<ViewGrou
view.getScrollX() - contentView.getLeft(),
view.getScrollY() - contentView.getTop());
Rect input = new Rect(requestedContentBounds);
// Expand input rect to get the requested rect to be in the center
int remainingHeight = view.getHeight() - view.getPaddingTop()
- view.getPaddingBottom() - input.height();
if (remainingHeight > 0) {
input.inset(0, -remainingHeight / 2);
}
// requestRect is now local to contentView as requestedContentBounds
// contentView (and each parent in turn if possible) will be scrolled
// (if necessary) to make all of requestedContent visible, (if possible!)
contentView.requestRectangleOnScreen(new Rect(requestedContentBounds), true);
contentView.requestRectangleOnScreen(input, true);
// update new offset between starting and current scroll position
scrollDelta = view.getScrollY() - mStartScrollY;