From 5ea7f03e25bffdbe9a2ae40b021dbb20e320bfb7 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Wed, 5 Apr 2023 13:15:32 +0200 Subject: [PATCH] Fix FooteredTextView measurements for overlong pill spans Together with https://github.com/vector-im/element-android/pull/8260, fixes https://github.com/SchildiChat/SchildiChat-android/issues/28 Change-Id: I3c11d1ec89383330fedb4a958d70e89047915024 --- .../im/vector/app/core/ui/views/AbstractFooteredTextView.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/core/ui/views/AbstractFooteredTextView.kt b/vector/src/main/java/im/vector/app/core/ui/views/AbstractFooteredTextView.kt index 01c573c740..ea13878733 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/AbstractFooteredTextView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/AbstractFooteredTextView.kt @@ -15,6 +15,7 @@ import im.vector.app.features.html.HtmlCodeSpan import io.noties.markwon.core.spans.EmphasisSpan import kotlin.math.ceil import kotlin.math.max +import kotlin.math.min /** * TextView that reserves space at the bottom for overlaying it with a footer, e.g. in a FrameLayout or RelativeLayout @@ -73,7 +74,7 @@ interface AbstractFooteredTextView { val looksLikeRtl = layout.isRtlCharAt(lastVisibleCharacter) */ - // Get required width for all lines + // Get required width for all lines (not using measuredWidth so wrap_content doesn't go match_parent if long lines enforced some line breaks) var maxLineWidth = 0f for (i in 0 until layout.lineCount) { // For some reasons, the getLineWidth is not working too well with RTL lines when rendering replies. @@ -87,6 +88,9 @@ interface AbstractFooteredTextView { max(layout.getLineWidth(i), maxLineWidth) } } + // Huge PillImageSpans might want to reserve more horizontal space with above approach than what is available, + // so ensure we don't give them more then super would, such that their auto-ellipsize feature works properly. + maxLineWidth = min(maxLineWidth, measuredWidth.toFloat()) // Fix wrap_content in multi-line texts by using maxLineWidth instead of measuredWidth here // (compare WrapWidthTextView.kt)