From bbb1b2b5170a59921167fae04790d34d123225a8 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Thu, 4 Jul 2024 17:50:17 +1000 Subject: [PATCH] Fix issue with span being the full length (#1528) --- .../securesms/util/RoundedBackgroundSpan.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/RoundedBackgroundSpan.kt b/app/src/main/java/org/thoughtcrime/securesms/util/RoundedBackgroundSpan.kt index ebefc9c50c..a4cf1b1e96 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/RoundedBackgroundSpan.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/RoundedBackgroundSpan.kt @@ -1,7 +1,6 @@ package org.thoughtcrime.securesms.util import android.content.Context -import android.content.res.Resources import android.graphics.Canvas import android.graphics.Paint import android.graphics.RectF @@ -50,6 +49,17 @@ class RoundedBackgroundSpan( override fun getSize( paint: Paint, text: CharSequence?, start: Int, end: Int, fm: Paint.FontMetricsInt? ): Int { + // If the span covers the whole text, and the height is not set, draw() will not be called for the span. + // To help with that we need to take the font metric into account + val metrics = paint.fontMetricsInt + if (fm != null) { + fm.top = metrics.top + fm.ascent = metrics.ascent + fm.descent = metrics.descent + + fm.bottom = metrics.bottom + } + return (paint.measureText(text, start, end) + 2 * paddingHorizontal).toInt() }