mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-27 14:40:22 +00:00
Fix elongated message bubbles when intentional newlines are present.
This commit is contained in:
committed by
Greyson Parrelli
parent
bfaaf20fd9
commit
fa13b464f8
@@ -34,6 +34,7 @@ import org.thoughtcrime.securesms.emoji.JumboEmoji;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -212,7 +213,7 @@ public class EmojiTextView extends AppCompatTextView {
|
||||
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
|
||||
float measuredTextWidth = hasMetricAffectingSpan(text) ? Layout.getDesiredWidth(text, getPaint()) : getPaint().measureText(text, 0, text.length());
|
||||
float measuredTextWidth = hasMetricAffectingSpan(text) ? Layout.getDesiredWidth(text, getPaint()) : getLongestLineWidth(text);
|
||||
int desiredWidth = (int) measuredTextWidth + getPaddingLeft() + getPaddingRight();
|
||||
|
||||
if (widthSpecMode == MeasureSpec.AT_MOST && desiredWidth < widthSpecSize) {
|
||||
@@ -232,6 +233,20 @@ public class EmojiTextView extends AppCompatTextView {
|
||||
return ((Spanned) text).nextSpanTransition(-1, text.length(), CharacterStyle.class) != text.length();
|
||||
}
|
||||
|
||||
private float getLongestLineWidth(@NonNull CharSequence text) {
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
long maxLines = getMaxLines() > 0 ? getMaxLines() : Long.MAX_VALUE;
|
||||
|
||||
return Arrays.stream(text.toString().split("\n"))
|
||||
.limit(maxLines)
|
||||
.map(s -> getPaint().measureText(s, 0, s.length()))
|
||||
.max(Float::compare)
|
||||
.orElse(0f);
|
||||
}
|
||||
|
||||
public int getLastLineWidth() {
|
||||
return lastLineWidth;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user