binding-collection-adapter icon indicating copy to clipboard operation
binding-collection-adapter copied to clipboard

MotionLayout + bindingcollectionadapter = 💔

Open c-b-h opened this issue 4 years ago • 1 comments

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.

buttons_not_appearing

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.

c-b-h avatar Sep 11 '20 09:09 c-b-h

Interesting issue, going to assign as a bug for now until exactly what is causing this is figured out.

evant avatar Sep 13 '20 20:09 evant