binding-collection-adapter
binding-collection-adapter copied to clipboard
MotionLayout + bindingcollectionadapter = 💔
Is this a general databinding issue or question? You are more likely to get a response from somewhere like StackOverflow.
Issue
Our team uses me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:4.0.0 extensively and hasn't encountered any major issues until recently. We have started to investigate how to use MotionLayout in our apps and faced a challenge when the widget is combined with this library.
I have created a tiny Android project that should be self-explanatory where a switch of the container of quiz__multiple from ConstraintLayout to MotionLayout causes the RecyclerView's elements not to be shown.
Some background
We are both feeding a ViewPager2 with a collection of a custom SubViewModels while each SubViewModel in turn has binding data that RecyclerView is fed with.
We are using ViewStub to conditionally inflate various (heavy) layouts. The inflated layouts are also data bound and need to explicitly be assigned a LifecycleOwner and we do that by hooking into ViewStub's data binding adapters:
override fun onInflate(stub: ViewStub, inflated: View) {
inflated.doOnAttach { view ->
DataBindingUtil.getBinding<ViewDataBinding>(view)!!.apply {
lifecycleOwner = ViewTreeLifecycleOwner.get(root)
setVariable(BR.subViewModel, this@SubViewModel)
}
}
}
The issue is that if the user doesn't interact with the (hidden) RecyclerView its content will not be shown.

My best guess is that this is due to the OnRebindCallback that BindingRecyclerViewAdapter registers. Note that the issue does not occur if the MotionLayout is swapped with ConstraintLayout. The animation seems to be the culprit.
Interesting issue, going to assign as a bug for now until exactly what is causing this is figured out.