dammy_abayomi
11/23/2020, 1:11 PMStateFlow 🤝 DataBinding in a similar way as LiveData do. It seems there isn’t a default implementation at the moment that supports it.
I found an example online which seems quite “burdensome” if one needs to implement it for a bigger project https://github.com/STAR-ZERO/sample-stateflow-databinding
Do you use StateFlow 🤝 DataBinding ? How do you connect them?flosch
11/23/2020, 1:14 PMnrobi
11/23/2020, 1:25 PM_mutableStateFlow: MutableStateFlow<T> and expose it like liveData: LiveData<T> get = _mutableStateFlow.asLiveData() similar as @flosch suggesteddammy_abayomi
11/23/2020, 1:28 PMdammy_abayomi
11/23/2020, 1:36 PMStateFlow object right from the XML files to regularly get its updated value.
I’d resolve to exposing the object to a LiveData to get that done.
Thanks again. CC: @flosch @nrobiMustafa Ozhan
12/17/2020, 5:23 PM<import type="androidx.lifecycle.FlowLiveDataConversions" />
and convert stateFlow to live data in xml like this
app:visibility="@{(FlowLiveDataConversions.asLiveData(vm.state.loading))}" />
but having this error
Cannot find a setter for <android.widget.ProgressBar app:visibility> that accepts parameter type 'androidx.lifecycle.LiveData<?>'dammy_abayomi
12/17/2020, 11:59 PMMustafa Ozhan
12/18/2020, 9:32 AM@BindingAdapter("visibility")
fun View.visibility(visible: Boolean) {
visibility = if (visible) {
bringToFront()
View.VISIBLE
} else {
View.GONE
}
}
So the problem now it is working with live data
app:visibility="@{vm.state.loadingLiveData}" />
but it gives error when i use stateFlow with asLiveData extension in XML
app:visibility="@{(FlowLiveDataConversions.asLiveData(vm.state.loadingStateDlow))}" />flosch
12/18/2020, 9:36 AM@BindingAdapter("visibility")
fun View.visibility(visibilityFlow: StateFlow<Boolean>) {
visibilityFlow.asLiveData(findViewTreeLifecycleOwner()) { visible ->
visibility = if (visible) {
bringToFront()
View.VISIBLE
} else {
View.GONE
}
}
}