From 50f66511d932e3555bb6de288987d657bd81bd7a Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Wed, 14 Dec 2022 02:53:38 -0800 Subject: [PATCH] Fix IllegalStateException caused by trying to snap to destination before initalizing page scrolls. Bug: 262256539 Test: swiped home several times Change-Id: I1d4b515f917e89c2ee0112a408499734222c6852 --- src/com/android/launcher3/PagedView.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index eb68adb3e8..80b1a8c019 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -1404,15 +1404,17 @@ public abstract class PagedView extends ViewGrou (isFling && !isVelocityLeft)) && mCurrentPage > 0) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - getPanelCount(); - snapToPageWithVelocity(finalPage, velocity); + runOnPageScrollsInitialized( + () -> snapToPageWithVelocity(finalPage, velocity)); } else if (((isSignificantMove && isDeltaLeft && !isFling) || (isFling && isVelocityLeft)) && mCurrentPage < getChildCount() - 1) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + getPanelCount(); - snapToPageWithVelocity(finalPage, velocity); + runOnPageScrollsInitialized( + () -> snapToPageWithVelocity(finalPage, velocity)); } else { - snapToDestination(); + runOnPageScrollsInitialized(this::snapToDestination); } } else { if (!mScroller.isFinished()) { @@ -1435,7 +1437,7 @@ public abstract class PagedView extends ViewGrou int finalPos = mScroller.getFinalX(); mNextPage = getDestinationPage(finalPos); - onNotSnappingToPageInFreeScroll(); + runOnPageScrollsInitialized(this::onNotSnappingToPageInFreeScroll); } invalidate(); } @@ -1449,7 +1451,7 @@ public abstract class PagedView extends ViewGrou case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged) { - snapToDestination(); + runOnPageScrollsInitialized(this::snapToDestination); } mEdgeGlowLeft.onRelease(); mEdgeGlowRight.onRelease();