Skip to content

Instantly share code, notes, and snippets.

@matthewrkula
Created June 18, 2020 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewrkula/647f9c96c00418bee1d00e72c329ece8 to your computer and use it in GitHub Desktop.
Save matthewrkula/647f9c96c00418bee1d00e72c329ece8 to your computer and use it in GitHub Desktop.
@BindingAdapter("onTextChanged")
fun onTextChanged(inputText: InputText, block: (String) -> Unit) {
inputText.addTextChangedListener(object : TextWatcher {
override fun onTextChanged(CharSequence s, int start, int before, int count) {
block(s.toString())
}
})
}
<layout>
<variable name="interactor" type="com.theathletic.profile.presenter"/>
...
<Input
...
app:onTextChanged="@{(text) -> interactor.onEmailChanged(text)}"
/>
</layout>
interface ProfileInterator {
fun onEmailChange(emailText: String)
}
class ProfilePresenter(...) : ProfileInteractor {
...
override fun onEmailChanged(emailText: String) {
updateState {
copy(email = emailText)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment