Fix rich text editor EditText not resizing properly in full screen (#7491)

* Fix rich text editor full screen mode

* Add changelog

* Address review comments.
This commit is contained in:
Jorge Martin Espinosa 2022-10-31 16:43:01 +01:00 committed by GitHub
parent 48cca9973b
commit 7ba1052bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

1
changelog.d/7491.bugfix Normal file
View File

@ -0,0 +1 @@
Fix rich text editor textfield not growing to fill parent on full screen.

View File

@ -54,8 +54,9 @@ class RichTextComposerLayout @JvmOverloads constructor(
private var currentConstraintSetId: Int = -1 private var currentConstraintSetId: Int = -1
private val animationDuration = 100L private val animationDuration = 100L
private val maxEditTextLinesWhenCollapsed = 12
private var isFullScreen = false private val isFullScreen: Boolean get() = currentConstraintSetId == R.layout.composer_rich_text_layout_constraint_set_fullscreen
var isTextFormattingEnabled = true var isTextFormattingEnabled = true
set(value) { set(value) {
@ -104,10 +105,10 @@ class RichTextComposerLayout @JvmOverloads constructor(
collapse(false) collapse(false)
views.richTextComposerEditText.addTextChangedListener( views.richTextComposerEditText.addTextChangedListener(
TextChangeListener({ callback?.onTextChanged(it) }, ::updateTextFieldBorder) TextChangeListener({ callback?.onTextChanged(it) }, { updateTextFieldBorder() })
) )
views.plainTextComposerEditText.addTextChangedListener( views.plainTextComposerEditText.addTextChangedListener(
TextChangeListener({ callback?.onTextChanged(it) }, ::updateTextFieldBorder) TextChangeListener({ callback?.onTextChanged(it) }, { updateTextFieldBorder() })
) )
views.composerRelatedMessageCloseButton.setOnClickListener { views.composerRelatedMessageCloseButton.setOnClickListener {
@ -196,8 +197,9 @@ class RichTextComposerLayout @JvmOverloads constructor(
button.isSelected = menuState.reversedActions.contains(action) button.isSelected = menuState.reversedActions.contains(action)
} }
private fun updateTextFieldBorder(isExpanded: Boolean) { private fun updateTextFieldBorder() {
val borderResource = if (isExpanded) { val isExpanded = editText.editableText.lines().count() > 1
val borderResource = if (isExpanded || isFullScreen) {
R.drawable.bg_composer_rich_edit_text_expanded R.drawable.bg_composer_rich_edit_text_expanded
} else { } else {
R.drawable.bg_composer_rich_edit_text_single_line R.drawable.bg_composer_rich_edit_text_single_line
@ -240,8 +242,21 @@ class RichTextComposerLayout @JvmOverloads constructor(
it.applyTo(this) it.applyTo(this)
} }
updateTextFieldBorder(newValue) updateTextFieldBorder()
updateEditTextVisibility() updateEditTextVisibility()
updateEditTextFullScreenState(views.richTextComposerEditText, newValue)
updateEditTextFullScreenState(views.plainTextComposerEditText, newValue)
}
private fun updateEditTextFullScreenState(editText: EditText, isFullScreen: Boolean) {
if (isFullScreen) {
editText.maxLines = Int.MAX_VALUE
// This is a workaround to fix incorrect scroll position when maximised
post { editText.requestLayout() }
} else {
editText.maxLines = maxEditTextLinesWhenCollapsed
}
} }
private fun applyNewConstraintSet(animate: Boolean, transitionComplete: (() -> Unit)?) { private fun applyNewConstraintSet(animate: Boolean, transitionComplete: (() -> Unit)?) {