Ensure that revealAmount = 0 doesn't leave an oval on the right side of the screen.

This is done by animating the bounds to a height of 0, and fixing a bug where if the height was 0, we wouldn't draw anything (we should draw the end color in that case). This also fixes a bug where the scrim was not properly initialized.

Bug: 187072550
Test: manual
Change-Id: I3b1224d196cff6045624a527f488f394929f7423
This commit is contained in:
Josh Tsuji
2021-05-04 12:15:26 -04:00
parent 1d92fd8123
commit ca0a24838a

View File

@@ -112,7 +112,12 @@ class PowerButtonReveal(
val powerButtonY: Float
) : LightRevealEffect {
private val OVAL_INITIAL_HEIGHT = 50f
/**
* How far off the side of the screen to start the power button reveal, in terms of percent of
* the screen width. This ensures that the initial part of the animation (where the reveal is
* just a sliver) starts just off screen.
*/
private val OFF_SCREEN_START_AMOUNT = 0.05f
private val WIDTH_INCREASE_MULTIPLIER = 1.25f
@@ -124,13 +129,13 @@ class PowerButtonReveal(
with(scrim) {
revealGradientEndColorAlpha = 1f - fadeAmount
setRevealGradientBounds(
width -
width * (1f + OFF_SCREEN_START_AMOUNT) -
width * WIDTH_INCREASE_MULTIPLIER * interpolatedAmount,
powerButtonY - (OVAL_INITIAL_HEIGHT / 2f) -
powerButtonY -
height * interpolatedAmount,
width * WIDTH_INCREASE_MULTIPLIER +
width * (1f + OFF_SCREEN_START_AMOUNT) +
width * WIDTH_INCREASE_MULTIPLIER * interpolatedAmount,
powerButtonY + (OVAL_INITIAL_HEIGHT / 2f) +
powerButtonY +
height * interpolatedAmount)
}
}
@@ -147,7 +152,7 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
* How much of the underlying views are revealed, in percent. 0 means they will be completely
* obscured and 1 means they'll be fully visible.
*/
var revealAmount: Float = 0f
var revealAmount: Float = 1f
set(value) {
if (field != value) {
field = value
@@ -213,6 +218,12 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
*/
private val shaderGradientMatrix = Matrix()
init {
revealEffect.setRevealAmountOnScrim(revealAmount, this)
setPaintColorFilter()
invalidate()
}
/**
* Sets bounds for the transparent oval gradient that reveals the views below the scrim. This is
* simply a helper method that sets [revealGradientCenter], [revealGradientWidth], and
@@ -231,6 +242,9 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
override fun onDraw(canvas: Canvas?) {
if (canvas == null || revealGradientWidth <= 0 || revealGradientHeight <= 0) {
if (revealAmount < 1f) {
canvas?.drawColor(revealGradientEndColor)
}
return
}