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

Commit

Permalink
[Android] Add releaseOnDetach parameter to EditorStyledText (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp authored Dec 28, 2023
1 parent e9e9048 commit 734dd4c
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import io.element.android.wysiwyg.display.TextDisplay
* @param resolveMentionDisplay A function to resolve the [TextDisplay] of a mention.
* @param resolveRoomMentionDisplay A function to resolve the [TextDisplay] of an `@room` mention.
* @param style The styles to use for any customisable elements.
* @param releaseOnDetach Whether to release the view when the composable is detached from the composition or not.
* Setting this to `false` is specially useful in Lazy composables that need to reuse these views. Defaults to `true`.
*/
@Composable
fun EditorStyledText(
Expand All @@ -37,6 +39,7 @@ fun EditorStyledText(
onLinkClickedListener: ((String) -> Unit) = {},
onTextLayout: (Layout) -> Unit = {},
style: RichTextEditorStyle = RichTextEditorDefaults.style(),
releaseOnDetach: Boolean = true,
) {
val typeface by style.text.rememberTypeface()
val mentionDisplayHandler = remember(resolveMentionDisplay, resolveRoomMentionDisplay) {
Expand All @@ -63,13 +66,16 @@ fun EditorStyledText(
view.applyStyleInCompose(style)
view.updateStyle(style.toStyleConfig(view.context), mentionDisplayHandler)
view.typeface = typeface
view.onLinkClickedListener = onLinkClickedListener
view.onTextLayout = onTextLayout
if (text is Spanned) {
view.setText(text, TextView.BufferType.SPANNABLE)
} else {
view.setHtml(text.toString())
}
view.onLinkClickedListener = onLinkClickedListener
view.onTextLayout = onTextLayout
}
},
onReset = { view: EditorStyledTextView ->
view.setText("", TextView.BufferType.SPANNABLE)
}.takeUnless { releaseOnDetach },
)
}

0 comments on commit 734dd4c

Please sign in to comment.