mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Merge pull request #4281 from vector-im/feature/aris/broken_edittext_4276
Fix Broken EditText when using FromEditTextItem
This commit is contained in:
commit
a7d5c6a437
2 changed files with 30 additions and 3 deletions
1
changelog.d/4276.bugfix
Normal file
1
changelog.d/4276.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fix Broken EditText when using FromEditTextItem
|
|
@ -18,6 +18,7 @@ package im.vector.app.features.form
|
|||
|
||||
import android.text.Editable
|
||||
import android.text.InputFilter
|
||||
import android.text.InputType
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.TextView
|
||||
|
@ -106,9 +107,9 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
|
|||
}
|
||||
|
||||
holder.textInputEditText.isEnabled = enabled
|
||||
inputType?.let { holder.textInputEditText.inputType = it }
|
||||
holder.textInputEditText.isSingleLine = singleLine
|
||||
holder.textInputEditText.imeOptions = imeOptions ?: EditorInfo.IME_ACTION_NONE
|
||||
|
||||
configureInputType(holder)
|
||||
configureImeOptions(holder)
|
||||
|
||||
holder.textInputEditText.addTextChangedListenerOnce(onTextChangeListener)
|
||||
holder.textInputEditText.setOnEditorActionListener(editorActionListener)
|
||||
|
@ -124,6 +125,31 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the inputType of the EditText, input type should be always defined
|
||||
* especially when we want to use a single line, we set the InputType to InputType.TYPE_CLASS_TEXT
|
||||
* while the default for the EditText is InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
||||
*/
|
||||
private fun configureInputType(holder: Holder) = holder.textInputEditText.setRawInputType(
|
||||
inputType ?: when (singleLine) {
|
||||
true -> InputType.TYPE_CLASS_TEXT
|
||||
false -> InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Configure the imeOptions of the EditText, when imeOptions are not defined by the developer
|
||||
* EditorInfo.IME_ACTION_NEXT will be used for singleLine EditTexts to disable "new line"
|
||||
* while EditorInfo.IME_ACTION_NONE will be used for all the other cases
|
||||
*/
|
||||
private fun configureImeOptions(holder: Holder) {
|
||||
holder.textInputEditText.imeOptions =
|
||||
imeOptions ?: when (singleLine) {
|
||||
true -> EditorInfo.IME_ACTION_NEXT
|
||||
false -> EditorInfo.IME_ACTION_NONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun shouldSaveViewState(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue