evant / binding-collection-adapter

Easy way to bind collections to listviews and recyclerviews with the new Android Data Binding framework
Apache License 2.0
1.92k stars 255 forks source link

MotionLayout + bindingcollectionadapter = 💔 #200

Open c-b-h opened 4 years ago

c-b-h commented 4 years ago

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.

evant commented 4 years ago

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