Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix send button blinking with RTE #8770

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/send_button_blinking.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix send button blinking once for each character you are typing in RTE.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
}
}