Snap to relative position to snappd task when dismissing

- Calculate the diff to snapped page scroll and apply in onLayout, so tasks won't jump after dismiss when not in snapped position
- In grid, always keep the relateive snapped page unchanged to avoid jump

Bug: 188793333
Test: manual
Change-Id: Id11c2d700dc55440de39cc7409d06a712cedc9bc
This commit is contained in:
Alex Chau
2021-06-15 16:29:19 +01:00
parent b14a7a2d16
commit ba61b98fca
2 changed files with 14 additions and 7 deletions

View File

@@ -104,6 +104,10 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
@ViewDebug.ExportedProperty(category = "launcher")
protected int mCurrentPage;
// Difference between current scroll position and mCurrentPage's page scroll. Used to maintain
// relative scroll position unchanged in updateCurrentPageScroll. Cleared when snapping to a
// page.
protected int mCurrentPageScrollDiff;
@ViewDebug.ExportedProperty(category = "launcher")
protected int mNextPage = INVALID_PAGE;
@@ -247,7 +251,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
// If the current page is invalid, just reset the scroll position to zero
int newPosition = 0;
if (0 <= mCurrentPage && mCurrentPage < getPageCount()) {
newPosition = getScrollForPage(mCurrentPage);
newPosition = getScrollForPage(mCurrentPage) + mCurrentPageScrollDiff;
}
mOrientationHandler.set(this, VIEW_SCROLL_TO, newPosition);
mScroller.startScroll(mScroller.getCurrX(), 0, newPosition - mScroller.getCurrX(), 0);
@@ -452,6 +456,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
* to provide custom behavior during animation.
*/
protected void onPageEndTransition() {
mCurrentPageScrollDiff = 0;
AccessibilityManagerCompat.sendScrollFinishedEventToTest(getContext());
AccessibilityManagerCompat.sendCustomAccessibilityEvent(getPageAt(mCurrentPage),
AccessibilityEvent.TYPE_VIEW_FOCUSED, null);