From f629b618a446a45b5b3d8d95290f0c170e4ea208 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Fri, 26 Jun 2020 18:58:39 -0700 Subject: [PATCH] Fixed an issue where scrolling didn't work anymore after going to landscape Because of the way linearlayout measures and because we never invalidated our measure cache, the measuring of the view would be skipped, leading to issues. We're now forcing the measurement to be invalidated when changing the measuredState. Fixes: 159719742 Test: use crosshatch, go to expanded qs, have 2 players. Rotate back and forth. Observe normal scrolling Change-Id: I32fc904f884b1032d173c4811576cdb5818bad22 --- .../systemui/media/MediaCarouselController.kt | 2 +- .../media/MediaCarouselScrollHandler.kt | 2 +- .../util/animation/TransitionLayout.kt | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt index 7c09accae6490..cd169244b910c 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt @@ -464,7 +464,7 @@ class MediaCarouselController @Inject constructor( val width = desiredHostState?.measurementInput?.width ?: 0 val height = desiredHostState?.measurementInput?.height ?: 0 if (width != carouselMeasureWidth && width != 0 || - height != carouselMeasureWidth && height != 0) { + height != carouselMeasureHeight && height != 0) { carouselMeasureWidth = width carouselMeasureHeight = height val playerWidthPlusPadding = carouselMeasureWidth + diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselScrollHandler.kt b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselScrollHandler.kt index ef2f71100e1a6..3096908aca215 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselScrollHandler.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselScrollHandler.kt @@ -243,7 +243,7 @@ class MediaCarouselScrollHandler( } val rotation = (1.0f - settingsOffset) * 50 settingsButton.rotation = rotation * -Math.signum(contentTranslation) - val alpha = MathUtils.map(0.5f, 1.0f, 0.0f, 1.0f, settingsOffset) + val alpha = MathUtils.saturate(MathUtils.map(0.5f, 1.0f, 0.0f, 1.0f, settingsOffset)) settingsButton.alpha = alpha settingsButton.visibility = if (alpha != 0.0f) View.VISIBLE else View.INVISIBLE settingsButton.translationX = newTranslationX diff --git a/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt b/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt index f39665671c5e0..3347cf6ca2a42 100644 --- a/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt +++ b/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt @@ -47,12 +47,29 @@ class TransitionLayout @JvmOverloads constructor( private var currentState: TransitionViewState = TransitionViewState() private var updateScheduled = false + private var desiredMeasureWidth = 0 + private var desiredMeasureHeight = 0 /** * The measured state of this view which is the one we will lay ourselves out with. This * may differ from the currentState if there is an external animation or transition running. * This state will not be used to measure the widgets, where the current state is preferred. */ var measureState: TransitionViewState = TransitionViewState() + set(value) { + val newWidth = value.width + val newHeight = value.height + if (newWidth != desiredMeasureWidth || newHeight != desiredMeasureHeight) { + desiredMeasureWidth = newWidth + desiredMeasureHeight = newHeight + // We need to make sure next time we're measured that our onMeasure will be called. + // Otherwise our parent thinks we still have the same height + if (isInLayout()) { + forceLayout() + } else { + requestLayout() + } + } + } private val preDrawApplicator = object : ViewTreeObserver.OnPreDrawListener { override fun onPreDraw(): Boolean { updateScheduled = false @@ -158,7 +175,7 @@ class TransitionLayout @JvmOverloads constructor( MeasureSpec.EXACTLY) child.measure(measureWidthSpec, measureHeightSpec) } - setMeasuredDimension(measureState.width, measureState.height) + setMeasuredDimension(desiredMeasureWidth, desiredMeasureHeight) } }