Fix long press crash on long polls.

This commit is contained in:
Michelle Tang
2025-12-11 17:34:18 -05:00
committed by Alex Hart
parent 1c30a8f38e
commit 2ca4748e00

View File

@@ -17,6 +17,8 @@ import org.thoughtcrime.securesms.util.hasNoBubble
object ConversationItemSelection {
const val MAX_SIZE: Long = 4096 * 4096
@JvmStatic
fun snapshotView(
target: InteractiveConversationElement,
@@ -45,7 +47,7 @@ object ConversationItemSelection {
): Bitmap {
val snapshotStrategy = target.getSnapshotStrategy()
if (snapshotStrategy != null) {
return createBitmap(target.root.width, target.root.height).applyCanvas {
return createSafeBitmap(target.root.width, target.root.height).applyCanvas {
snapshotStrategy.snapshot(this)
}
}
@@ -94,7 +96,7 @@ object ConversationItemSelection {
if (hasReaction) {
bitmapHeight += (reactionsView.height - DimensionUnit.DP.toPixels(4f)).toInt()
}
return createBitmap(bodyBubble.width, bitmapHeight).applyCanvas {
return createSafeBitmap(bodyBubble.width, bitmapHeight).applyCanvas {
if (drawConversationItem) {
bodyBubble.draw(this)
}
@@ -121,6 +123,16 @@ object ConversationItemSelection {
bodyBubble.scaleY = originalScale
}
}
private fun createSafeBitmap(width: Int, height: Int): Bitmap {
return if (width * height < MAX_SIZE) {
createBitmap(width, height)
} else {
// Since this is only called in rare cases where the height is incredibly large / 'Read more' has not been triggered yet,
// used a general solution instead of something more algorithmic.
createBitmap(width, height / 2)
}
}
}
private fun ViewGroup.destroyAllDrawingCaches() {