From 58158516e7cbece9db10496d750bcb28c8c5f516 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Tue, 16 Jun 2020 19:45:02 -0700 Subject: [PATCH] Fix clipping while scrolling Bug: 157926365 Test: manual Change-Id: I066eda619569cb68a49424afbdab9e25a0082ea6 --- .../util/animation/TransitionLayout.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 eeca1e38abb00..e5b126d7ff7f2 100644 --- a/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt +++ b/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt @@ -17,6 +17,7 @@ package com.android.systemui.util.animation import android.content.Context +import android.graphics.Canvas import android.graphics.PointF import android.graphics.Rect import android.util.AttributeSet @@ -37,6 +38,7 @@ class TransitionLayout @JvmOverloads constructor( defStyleAttr: Int = 0 ) : ConstraintLayout(context, attrs, defStyleAttr) { + private val boundsRect = Rect() private val originalGoneChildrenSet: MutableSet = mutableSetOf() private val originalViewAlphas: MutableMap = mutableMapOf() private var measureAsConstraint: Boolean = false @@ -147,16 +149,26 @@ class TransitionLayout @JvmOverloads constructor( } } + override fun dispatchDraw(canvas: Canvas?) { + val clip = !boundsRect.isEmpty + if (clip) { + canvas?.save() + canvas?.clipRect(boundsRect) + } + super.dispatchDraw(canvas) + if (clip) { + canvas?.restore() + } + } + private fun updateBounds() { val layoutLeft = left val layoutTop = top setLeftTopRightBottom(layoutLeft, layoutTop, layoutLeft + currentState.width, layoutTop + currentState.height) - val bounds = clipBounds ?: Rect() - bounds.set(left, top, right, bottom) - clipBounds = bounds translationX = currentState.translation.x translationY = currentState.translation.y + boundsRect.set(0, 0, (width + translationX).toInt(), (height + translationY).toInt()) } /**