Add some comments and default values

This commit is contained in:
Benoit Marty 2021-12-13 20:34:44 +01:00
parent 78a7a61d07
commit 6e646b12b5
2 changed files with 7 additions and 8 deletions

View file

@ -17,6 +17,8 @@
package im.vector.app.features.home.room.detail.timeline.item package im.vector.app.features.home.room.detail.timeline.item
data class BindingOptions( data class BindingOptions(
val canUseTextFuture: Boolean, // Allowed by default
val preventMutation: Boolean val canUseTextFuture: Boolean = true,
// No need to prevent mutation by default
val preventMutation: Boolean = false
) )

View file

@ -30,15 +30,12 @@ class SpanUtils @Inject constructor() {
val emojiCharSequence = EmojiCompat.get().process(charSequence) val emojiCharSequence = EmojiCompat.get().process(charSequence)
if (emojiCharSequence !is Spanned) { if (emojiCharSequence !is Spanned) {
return BindingOptions( return BindingOptions()
canUseTextFuture = true,
preventMutation = false
)
} }
return BindingOptions( return BindingOptions(
canUseTextFuture = canUseTextFuture(emojiCharSequence), canUseTextFuture = canUseTextFuture(emojiCharSequence),
preventMutation = preventMutation(emojiCharSequence) preventMutation = mustPreventMutation(emojiCharSequence)
) )
} }
@ -55,7 +52,7 @@ class SpanUtils @Inject constructor() {
} }
// Workaround for setting text during binding which mutate the text itself // Workaround for setting text during binding which mutate the text itself
private fun preventMutation(spanned: Spanned): Boolean { private fun mustPreventMutation(spanned: Spanned): Boolean {
return spanned return spanned
.getSpans(0, spanned.length, Any::class.java) .getSpans(0, spanned.length, Any::class.java)
.any { it is MetricAffectingSpan } .any { it is MetricAffectingSpan }