Skip to content

Commit ffb8b10

Browse files
committed
adding extension for acting on textinputlayout text changes
1 parent a02141c commit ffb8b10

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,18 @@ fun TextInputLayout.content() = editText().text.toString()
4444
fun TextInputLayout.hasContent() = !editText().text.isNullOrEmpty()
4545

4646
fun TextInputLayout.clearErrorOnChange(lifecycleOwner: LifecycleOwner) {
47-
editText().textChanges()
47+
editText()
48+
.textChanges()
4849
.onEach { error = null }
4950
.launchIn(lifecycleOwner.lifecycleScope)
5051
}
5152

53+
fun TextInputLayout.onTextChange(lifecycleOwner: LifecycleOwner, action: (CharSequence) -> Unit) {
54+
editText().textChanges()
55+
.onEach(action)
56+
.launchIn(lifecycleOwner.lifecycleScope)
57+
}
58+
5259
fun TextInputLayout.associateContentStateWith(button: View, enabledPredicate: (String) -> Boolean = { it.isNotEmpty() }) {
5360
button.isEnabled = enabledPredicate(content())
5461
editText().addTextChangedListener(object : SimpleTextWatcher() {

0 commit comments

Comments
 (0)