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
This commit is contained in:
SpiritCroc 2023-04-05 13:15:32 +02:00
parent ea2a0e2193
commit 5ea7f03e25

View file

@ -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)