Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Remove workaround for excessive recomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyandrew committed Nov 14, 2023
1 parent 7836f40 commit 297427f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class MainActivity : ComponentActivity() {
state = state,
modifier = Modifier.fillMaxWidth().padding(10.dp),
style = RichTextEditorDefaults.style(),
onError = Timber::e,
onError = { Timber.e(it) },
resolveMentionDisplay = { _,_ -> TextDisplay.Pill },
resolveRoomMentionDisplay = { TextDisplay.Pill },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,16 @@ fun EditorStyledText(
factory = { context ->
EditorStyledTextView(context)
},
// The `update` lambda is called when the view is first created, and then again whenever the actual `update` lambda changes. That is, it's replaced with
// a new lambda capturing different variables from the surrounding scope. However, there seems to be an issue that causes the `update` lambda to change
// more than it's strictly necessary. To avoid this, we can use a `remember` block to cache the `update` lambda, and only update it when needed.
update = remember(style, typeface, mentionDisplayHandler, text, onLinkClickedListener) {
{ view ->
view.applyStyleInCompose(style)
view.typeface = typeface
view.updateStyle(style.toStyleConfig(view.context), mentionDisplayHandler)
if (text is Spanned) {
view.setText(text, TextView.BufferType.SPANNABLE)
} else {
view.setHtml(text.toString())
}
view.onLinkClickedListener = onLinkClickedListener
update = { view ->
view.applyStyleInCompose(style)
view.typeface = typeface
view.updateStyle(style.toStyleConfig(view.context), mentionDisplayHandler)
if (text is Spanned) {
view.setText(text, TextView.BufferType.SPANNABLE)
} else {
view.setHtml(text.toString())
}
view.onLinkClickedListener = onLinkClickedListener
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.element.android.wysiwyg.display.TextDisplay
import io.element.android.wysiwyg.utils.RustErrorCollector
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber


/**
Expand Down Expand Up @@ -168,16 +169,12 @@ private fun RealEditor(

view
},
// The `update` lambda is called when the view is first created, and then again whenever the actual `update` lambda changes. That is, it's replaced with
// a new lambda capturing different variables from the surrounding scope. However, there seems to be an issue that causes the `update` lambda to change
// more than it's strictly necessary. To avoid this, we can use a `remember` block to cache the `update` lambda, and only update it when needed.
update = remember(style, typeface, mentionDisplayHandler, onError) {
{ view ->
view.applyStyleInCompose(style)
view.typeface = typeface
view.updateStyle(style.toStyleConfig(view.context), mentionDisplayHandler)
view.rustErrorCollector = RustErrorCollector(onError)
}
update = { view ->
Timber.i("RichTextEditor update() called")
view.applyStyleInCompose(style)
view.typeface = typeface
view.updateStyle(style.toStyleConfig(view.context), mentionDisplayHandler)
view.rustErrorCollector = RustErrorCollector(onError)
}
)
}
Expand Down

0 comments on commit 297427f

Please sign in to comment.