From 21d685f981a869106e032014fe22826876acb2eb Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 4 Mar 2024 10:22:35 +0100 Subject: [PATCH] Fix send button blinking with RTE --- changelog.d/send_button_blinking.bugfix | 1 + .../detail/composer/RichTextComposerLayout.kt | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 changelog.d/send_button_blinking.bugfix diff --git a/changelog.d/send_button_blinking.bugfix b/changelog.d/send_button_blinking.bugfix new file mode 100644 index 0000000000..d6359a659f --- /dev/null +++ b/changelog.d/send_button_blinking.bugfix @@ -0,0 +1 @@ +Fix send button blinking once for each character you are typing in RTE. diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/RichTextComposerLayout.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/RichTextComposerLayout.kt index b0923885e8..a0d28be365 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/RichTextComposerLayout.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/RichTextComposerLayout.kt @@ -45,7 +45,9 @@ import com.google.android.material.shape.MaterialShapeDrawable import im.vector.app.R import im.vector.app.core.extensions.setTextIfDifferent import im.vector.app.core.extensions.showKeyboard +import im.vector.app.core.utils.Debouncer import im.vector.app.core.utils.DimensionConverter +import im.vector.app.core.utils.createUIHandler import im.vector.app.databinding.ComposerRichTextLayoutBinding import im.vector.app.databinding.ViewRichTextMenuButtonBinding import im.vector.app.features.home.room.detail.composer.images.UriContentListener @@ -195,10 +197,16 @@ internal class RichTextComposerLayout @JvmOverloads constructor( renderComposerMode(MessageComposerMode.Normal(null)) views.richTextComposerEditText.addTextChangedListener( - TextChangeListener({ callback?.onTextChanged(it) }, { updateTextFieldBorder(isFullScreen) }) + TextChangeListener( + onTextChanged = { + callback?.onTextChanged(it) + }, + onExpandedChanged = { updateTextFieldBorder(isFullScreen) }) ) views.plainTextComposerEditText.addTextChangedListener( - TextChangeListener({ callback?.onTextChanged(it) }, { updateTextFieldBorder(isFullScreen) }) + TextChangeListener({ + callback?.onTextChanged(it) + }, { updateTextFieldBorder(isFullScreen) }) ) ViewCompat.setOnReceiveContentListener( views.richTextComposerEditText, @@ -516,18 +524,21 @@ internal class RichTextComposerLayout @JvmOverloads constructor( private val onTextChanged: (s: Editable) -> Unit, private val onExpandedChanged: (isExpanded: Boolean) -> Unit, ) : TextWatcher { + + private val debouncer = Debouncer(createUIHandler()) private var previousTextWasExpanded = false override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} override fun afterTextChanged(s: Editable) { - onTextChanged.invoke(s) - - val isExpanded = s.lines().count() > 1 - if (previousTextWasExpanded != isExpanded) { - onExpandedChanged(isExpanded) + debouncer.debounce("afterTextChanged", 50L) { + onTextChanged.invoke(s) + val isExpanded = s.lines().count() > 1 + if (previousTextWasExpanded != isExpanded) { + onExpandedChanged(isExpanded) + } + previousTextWasExpanded = isExpanded } - previousTextWasExpanded = isExpanded } } }