From 001896d244daea817844317bc88051cc08387c0c Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 9 Apr 2026 22:02:46 -0400 Subject: [PATCH] Fix image transition animation. --- .../RecycledBitmapGuardDrawable.kt | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediapreview/RecycledBitmapGuardDrawable.kt b/app/src/main/java/org/thoughtcrime/securesms/mediapreview/RecycledBitmapGuardDrawable.kt index fd72f62230..f04c1dc81e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediapreview/RecycledBitmapGuardDrawable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/mediapreview/RecycledBitmapGuardDrawable.kt @@ -1,8 +1,9 @@ package org.thoughtcrime.securesms.mediapreview import android.graphics.Canvas +import android.graphics.ColorFilter +import android.graphics.PixelFormat import android.graphics.drawable.Drawable -import android.graphics.drawable.DrawableWrapper /** * A wrapper that skips drawing upon failure. This is to guard against situations where we may @@ -12,12 +13,43 @@ import android.graphics.drawable.DrawableWrapper * (like transition animations) where having a bitmap isn't strictly necessary, and we'd rather * show nothing than crash or have to manage the bitmap lifecycle ourselves. */ -class RecycledBitmapGuardDrawable(drawable: Drawable) : DrawableWrapper(drawable) { +class RecycledBitmapGuardDrawable(private val inner: Drawable) : Drawable() { + + init { + val b = inner.bounds + setBounds(b.left, b.top, b.right, b.bottom) + } + override fun draw(canvas: Canvas) { + val savedBounds = inner.copyBounds() + inner.setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom) try { - super.draw(canvas) + inner.draw(canvas) } catch (_: RuntimeException) { // Bitmap was recycled — nothing to draw. + } finally { + inner.setBounds(savedBounds.left, savedBounds.top, savedBounds.right, savedBounds.bottom) } } + + override fun getIntrinsicWidth(): Int { + return inner.intrinsicWidth + } + + override fun getIntrinsicHeight(): Int { + return inner.intrinsicHeight + } + + override fun setAlpha(alpha: Int) { + inner.alpha = alpha + } + + override fun setColorFilter(colorFilter: ColorFilter?) { + inner.colorFilter = colorFilter + } + + @Deprecated("Deprecated in Java", ReplaceWith("PixelFormat.TRANSLUCENT", "android.graphics.PixelFormat")) + override fun getOpacity(): Int { + return PixelFormat.TRANSLUCENT + } }