Merge pull request #4790 from vector-im/feature/adm/emoji-recycling

Timeline recycling crash
This commit is contained in:
Benoit Marty 2022-01-06 14:55:29 +01:00 committed by GitHub
commit 296929e179
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 14 deletions

1
changelog.d/4789.bugfix Normal file
View file

@ -0,0 +1 @@
Fixing crashes when quickly scrolling or restoring the room timeline

View file

@ -92,29 +92,27 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
it.bind(holder.messageView)
}
}
val textFuture = if (bindingOptions?.canUseTextFuture.orFalse()) {
PrecomputedTextCompat.getTextFuture(
message?.charSequence ?: "",
TextViewCompat.getTextMetricsParams(holder.messageView),
null)
} else {
null
message?.charSequence.let { charSequence ->
markwonPlugins?.forEach { plugin -> plugin.beforeSetText(holder.messageView, charSequence as Spanned) }
}
markwonPlugins?.forEach { plugin -> plugin.beforeSetText(holder.messageView, message?.charSequence as Spanned) }
super.bind(holder)
holder.messageView.movementMethod = movementMethod
renderSendState(holder.messageView, holder.messageView)
holder.messageView.onClick(attributes.itemClickListener)
holder.messageView.onLongClickIgnoringLinks(attributes.itemLongClickListener)
if (bindingOptions?.canUseTextFuture.orFalse()) {
holder.messageView.setTextFuture(textFuture)
} else {
holder.messageView.text = message?.charSequence
}
holder.messageView.setTextWithEmojiSupport(message?.charSequence, bindingOptions)
markwonPlugins?.forEach { plugin -> plugin.afterSetText(holder.messageView) }
}
private fun AppCompatTextView.setTextWithEmojiSupport(message: CharSequence?, bindingOptions: BindingOptions?) {
if (bindingOptions?.canUseTextFuture.orFalse() && message != null) {
val textFuture = PrecomputedTextCompat.getTextFuture(message, TextViewCompat.getTextMetricsParams(this), null)
setTextFuture(textFuture)
} else {
text = message
}
}
override fun unbind(holder: Holder) {
super.unbind(holder)
previewUrlViewUpdater.previewUrlView = null