Fix bullet points not having leading margin on timeline items (#4536)

* Fix bullet points not having leading margin on timeline items

* Remove other usages of `SpannableString` constructor, use either `valueOf` to reuse the existing value or `SpannedString` instead if the spans don't have to change
This commit is contained in:
Jorge Martin Espinosa
2025-04-07 10:50:45 +02:00
committed by GitHub
parent a63dffdcef
commit dac0eb6762
5 changed files with 8 additions and 10 deletions

View File

@@ -7,7 +7,7 @@
package io.element.android.features.messages.impl.timeline.components.event
import android.text.SpannableString
import android.text.SpannedString
import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.layout.Box
import androidx.compose.material3.LocalContentColor
@@ -71,7 +71,7 @@ fun TimelineItemTextView(
internal fun getTextWithResolvedMentions(content: TimelineItemTextBasedContent): CharSequence {
val mentionSpanUpdater = LocalMentionSpanUpdater.current
val bodyWithResolvedMentions = mentionSpanUpdater.rememberMentionSpans(content.formattedBody)
return SpannableString(bodyWithResolvedMentions)
return SpannedString.valueOf(bodyWithResolvedMentions)
}
@PreviewsDayNight

View File

@@ -135,7 +135,7 @@ fun ClickableLinkText(
fun AnnotatedString.linkify(linkStyle: SpanStyle): AnnotatedString {
val original = this
val spannable = SpannableString(this.text)
val spannable = SpannableString.valueOf(this.text)
LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS or Linkify.PHONE_NUMBERS or Linkify.EMAIL_ADDRESSES)
val spans = spannable.getSpans(0, spannable.length, URLSpan::class.java)

View File

@@ -8,7 +8,7 @@
package io.element.android.libraries.designsystem.text
import android.graphics.Typeface
import android.text.SpannableString
import android.text.SpannedString
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.text.style.UnderlineSpan
@@ -26,7 +26,7 @@ import io.element.android.compound.theme.LinkColor
fun String.toAnnotatedString(): AnnotatedString = buildAnnotatedString {
append(this@toAnnotatedString)
val spannable = SpannableString(this@toAnnotatedString)
val spannable = SpannedString.valueOf(this@toAnnotatedString)
spannable.getSpans(0, spannable.length, Any::class.java).forEach { span ->
val start = spannable.getSpanStart(span)
val end = spannable.getSpanEnd(span)

View File

@@ -16,11 +16,11 @@ import io.element.android.libraries.core.extensions.orEmpty
@Stable
class StableCharSequence(initialText: CharSequence = "") {
private var value by mutableStateOf<SpannableString>(SpannableString(initialText))
private var value by mutableStateOf<SpannableString>(SpannableString.valueOf(initialText))
private var needsDisplaying by mutableStateOf(false)
fun update(newText: CharSequence?, needsDisplaying: Boolean) {
value = SpannableString(newText.orEmpty())
value = SpannableString.valueOf(newText.orEmpty())
this.needsDisplaying = needsDisplaying
}

View File

@@ -9,7 +9,6 @@ package io.element.android.libraries.textcomposer.model
import android.os.Parcelable
import android.text.Spannable
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.Spanned
import androidx.compose.runtime.Composable
@@ -118,8 +117,7 @@ class MarkdownTextEditorState(
}
fun getMentions(): List<IntentionalMention> {
val text = SpannableString(text.value())
val mentionSpans = text.getMentionSpans()
val mentionSpans = text.value().getMentionSpans()
return mentionSpans.mapNotNull { mentionSpan ->
when (mentionSpan.type) {
is MentionType.User -> IntentionalMention.User(mentionSpan.type.userId)