Skip to content

Commit 21d685f

Browse files
committed
Fix send button blinking with RTE
1 parent 79462bc commit 21d685f

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix send button blinking once for each character you are typing in RTE.

vector/src/main/java/im/vector/app/features/home/room/detail/composer/RichTextComposerLayout.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ import com.google.android.material.shape.MaterialShapeDrawable
4545
import im.vector.app.R
4646
import im.vector.app.core.extensions.setTextIfDifferent
4747
import im.vector.app.core.extensions.showKeyboard
48+
import im.vector.app.core.utils.Debouncer
4849
import im.vector.app.core.utils.DimensionConverter
50+
import im.vector.app.core.utils.createUIHandler
4951
import im.vector.app.databinding.ComposerRichTextLayoutBinding
5052
import im.vector.app.databinding.ViewRichTextMenuButtonBinding
5153
import im.vector.app.features.home.room.detail.composer.images.UriContentListener
@@ -195,10 +197,16 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
195197
renderComposerMode(MessageComposerMode.Normal(null))
196198

197199
views.richTextComposerEditText.addTextChangedListener(
198-
TextChangeListener({ callback?.onTextChanged(it) }, { updateTextFieldBorder(isFullScreen) })
200+
TextChangeListener(
201+
onTextChanged = {
202+
callback?.onTextChanged(it)
203+
},
204+
onExpandedChanged = { updateTextFieldBorder(isFullScreen) })
199205
)
200206
views.plainTextComposerEditText.addTextChangedListener(
201-
TextChangeListener({ callback?.onTextChanged(it) }, { updateTextFieldBorder(isFullScreen) })
207+
TextChangeListener({
208+
callback?.onTextChanged(it)
209+
}, { updateTextFieldBorder(isFullScreen) })
202210
)
203211
ViewCompat.setOnReceiveContentListener(
204212
views.richTextComposerEditText,
@@ -516,18 +524,21 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
516524
private val onTextChanged: (s: Editable) -> Unit,
517525
private val onExpandedChanged: (isExpanded: Boolean) -> Unit,
518526
) : TextWatcher {
527+
528+
private val debouncer = Debouncer(createUIHandler())
519529
private var previousTextWasExpanded = false
520530

521531
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
522532
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
523533
override fun afterTextChanged(s: Editable) {
524-
onTextChanged.invoke(s)
525-
526-
val isExpanded = s.lines().count() > 1
527-
if (previousTextWasExpanded != isExpanded) {
528-
onExpandedChanged(isExpanded)
534+
debouncer.debounce("afterTextChanged", 50L) {
535+
onTextChanged.invoke(s)
536+
val isExpanded = s.lines().count() > 1
537+
if (previousTextWasExpanded != isExpanded) {
538+
onExpandedChanged(isExpanded)
539+
}
540+
previousTextWasExpanded = isExpanded
529541
}
530-
previousTextWasExpanded = isExpanded
531542
}
532543
}
533544
}

0 commit comments

Comments
 (0)