adding extension for acting on textinputlayout text changes
This commit is contained in:
parent
a02141c7c2
commit
ffb8b10f66
|
@ -44,11 +44,18 @@ fun TextInputLayout.content() = editText().text.toString()
|
|||
fun TextInputLayout.hasContent() = !editText().text.isNullOrEmpty()
|
||||
|
||||
fun TextInputLayout.clearErrorOnChange(lifecycleOwner: LifecycleOwner) {
|
||||
editText().textChanges()
|
||||
editText()
|
||||
.textChanges()
|
||||
.onEach { error = null }
|
||||
.launchIn(lifecycleOwner.lifecycleScope)
|
||||
}
|
||||
|
||||
fun TextInputLayout.onTextChange(lifecycleOwner: LifecycleOwner, action: (CharSequence) -> Unit) {
|
||||
editText().textChanges()
|
||||
.onEach(action)
|
||||
.launchIn(lifecycleOwner.lifecycleScope)
|
||||
}
|
||||
|
||||
fun TextInputLayout.associateContentStateWith(button: View, enabledPredicate: (String) -> Boolean = { it.isNotEmpty() }) {
|
||||
button.isEnabled = enabledPredicate(content())
|
||||
editText().addTextChangedListener(object : SimpleTextWatcher() {
|
||||
|
|
Loading…
Reference in New Issue