mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-02 20:26:47 +01:00
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:
parent
48cca9973b
commit
7ba1052bcf
1
changelog.d/7491.bugfix
Normal file
1
changelog.d/7491.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix rich text editor textfield not growing to fill parent on full screen.
|
@ -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)?) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user