airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.52k stars 726 forks source link

No animation when the switch is rebound #765

Open beeete2 opened 5 years ago

beeete2 commented 5 years ago

I am using Epoxy to make a list that contains the Switch. Scrolling the list, Recycler unbinds the View that contains the switch, and there is a phenomenon that the switch does not animate when it is rebound. I tried the same with RecyclerView.Adapter, but the switch was animated.

The switch uses AppCompat SwitchCompat, and the animation of the switch is realized by the following code.

if (getWindowToken() != null && ViewCompat.isLaidOut(this)) {
    animateThumbToCheckedState(checked);
} else {
    // Immediately move the thumb to the new position.
    cancelPositionAnimator();
    setThumbPosition(checked ? 1 : 0);
}

isLaidOut will return false if the recycled View is rebound.

We cope by the following workaround now.

But, performance is very bad because inflate is done every time. NeverReyclerViewPool is a self-made class. RecycledViewPool#getRecycledView returns null for View that includes Switch.

Is there a way to make the switch animate even if it is recycled?

RecyclerView Adapter

Epoxy Adapter

The program has been uploaded to the following repository. https://github.com/beeete2/android-recyclerview-example/tree/animation

lee-heejin commented 5 years ago

having a same issue

Shusek commented 1 year ago

Do you have any other ideas for workaround or we should report it for google tracker?