Skip to content

Commit

Permalink
Rich text editor: improve performance when changing composer mode (#7691
Browse files Browse the repository at this point in the history
)

* Rich text editor: improve performance when changing composer mode

* Add changelog

* Make `MessageComposerMode.Quote` and `Reply` data classes

* Re-arrange code to fix composer not being emptied when sneding a message
  • Loading branch information
jmartinesp authored Dec 12, 2022
1 parent a121670 commit c523e14
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/7691.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rich Text Editor: improve performance when entering reply/edit/quote mode.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
else -> return
}

(composer as? RichTextComposerLayout)?.setFullScreen(setFullScreen)
(composer as? RichTextComposerLayout)?.setFullScreen(setFullScreen, true)

messageComposerViewModel.handle(MessageComposerAction.SetFullScreen(setFullScreen))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ sealed interface MessageComposerMode {

sealed class Special(open val event: TimelineEvent, open val defaultContent: CharSequence) : MessageComposerMode
data class Edit(override val event: TimelineEvent, override val defaultContent: CharSequence) : Special(event, defaultContent)
class Quote(override val event: TimelineEvent, override val defaultContent: CharSequence) : Special(event, defaultContent)
class Reply(override val event: TimelineEvent, override val defaultContent: CharSequence) : Special(event, defaultContent)
data class Quote(override val event: TimelineEvent, override val defaultContent: CharSequence) : Special(event, defaultContent)
data class Reply(override val event: TimelineEvent, override val defaultContent: CharSequence) : Special(event, defaultContent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
// There is no need to persist these values since they're always updated by the parent fragment
private var isFullScreen = false
private var hasRelatedMessage = false
private var composerMode: MessageComposerMode? = null

var isTextFormattingEnabled = true
set(value) {
Expand Down Expand Up @@ -114,9 +115,15 @@ internal class RichTextComposerLayout @JvmOverloads constructor(

private val dimensionConverter = DimensionConverter(resources)

fun setFullScreen(isFullScreen: Boolean) {
fun setFullScreen(isFullScreen: Boolean, animated: Boolean) {
if (!animated && views.composerLayout.layoutParams != null) {
views.composerLayout.updateLayoutParams<ViewGroup.LayoutParams> {
height =
if (isFullScreen) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT
}
}
editText.updateLayoutParams<ViewGroup.LayoutParams> {
height = if (isFullScreen) 0 else ViewGroup.LayoutParams.WRAP_CONTENT
height = if (isFullScreen) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT
}

updateTextFieldBorder(isFullScreen)
Expand Down Expand Up @@ -371,7 +378,11 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
override fun renderComposerMode(mode: MessageComposerMode) {
if (mode is MessageComposerMode.Special) {
views.composerModeGroup.isVisible = true
replaceFormattedContent(mode.defaultContent)
if (isTextFormattingEnabled) {
replaceFormattedContent(mode.defaultContent)
} else {
views.plainTextComposerEditText.setText(mode.defaultContent)
}
hasRelatedMessage = true
editText.showKeyboard(andRequestFocus = true)
} else {
Expand All @@ -383,10 +394,14 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
views.plainTextComposerEditText.setText(text)
}
}
views.sendButton.contentDescription = resources.getString(R.string.action_send)
hasRelatedMessage = false
}

updateTextFieldBorder(isFullScreen)

if (this.composerMode == mode) return
this.composerMode = mode

views.sendButton.apply {
if (mode is MessageComposerMode.Edit) {
contentDescription = resources.getString(R.string.action_save)
Expand All @@ -397,8 +412,6 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
}
}

updateTextFieldBorder(isFullScreen)

when (mode) {
is MessageComposerMode.Edit -> {
views.composerModeTitleView.setText(R.string.editing)
Expand Down

0 comments on commit c523e14

Please sign in to comment.