Skip to content

Commit

Permalink
Fix TopBottomShader#createShader misbehaving when width or `heigh…
Browse files Browse the repository at this point in the history
…t` is zero

Co-authored-by: Patryk Goworowski <[email protected]>
  • Loading branch information
patrickmichalik and Gowsky committed Apr 20, 2024
1 parent a2ffd63 commit 1eb6718
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class TopBottomShader(
): Shader {
val width = (right - left).toInt()
val height = (bottom - top).toInt()
if (width == 0 || height == 0) return EmptyBitmapShader
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
if (splitY > 0f) {
Expand Down Expand Up @@ -84,4 +85,9 @@ public class TopBottomShader(
topShader == other.topShader && bottomShader == other.bottomShader && splitY == other.splitY

override fun hashCode(): Int = 31 * topShader.hashCode() + bottomShader.hashCode()

private companion object {
val EmptyBitmapShader =
BitmapShader(Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
}
}

0 comments on commit 1eb6718

Please sign in to comment.