1 year ago
#98983
Justin
Android Two-way binding and @InverseBindingAdapter doesn't work in Modular Architecture project
Having Modular Architecture project. Reusable custom views are being moved to core-ui module. Features (fragments, sheets, etc) at the moment are still in app module.
Before migrating custom views with @InverseBindingAdapter
(two-way binding) from app to core-ui module everything worked fine. After moving custom SearchView
with it's two-way bindings to separate module those binding errors appeared.
The attribute 'app:queryAttrChanged' is generated and reserved for two-way data binding so an expression cannot be assigned to it
Moving back to app module, everything works fine.
All other custom views with @BindingAdapter
(one way binding) works fine after migrating to core-ui. So something is wrong with @InverseBindingAdapter
.
I wasn't able to find any Modular Architecture Android project, which would use two-way binding in it. Also zero search results were found for error provided above. Any ideas where could be the problem?
@BindingAdapter(value = ["queryAttrChanged"])
fun setQueryAttrChanged(searchView: SearchView, listener: InverseBindingListener) {
searchView.binding?.viewSearchText?.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
listener.onChange()
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) = Unit
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) = Unit
})
}
@JvmStatic
@BindingAdapter("query")
fun setQuery(searchView: SearchView, value: String?) {
if (value != searchView.binding?.viewSearchText?.text.toString()) {
searchView.binding?.viewSearchText?.setText(value)
}
}
@InverseBindingAdapter(attribute = "query")
fun getQuery(searchView: SearchView): String {
return searchView.binding?.viewSearchText?.text.toString()
}
<com.foo.com.core_ui.utils.ui.views.SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:query="@={viewmodel.mutableLiveData.searchQuery}"
app:queryAttrChanged="@{() -> viewmodel.onSearchQueryChanged()}" />
android
two-way-binding
modularization
android-multi-module
0 Answers
Your Answer