epoxy icon indicating copy to clipboard operation
epoxy copied to clipboard

No animation when the switch is rebound

Open beeete2 opened this issue 5 years ago • 2 comments

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.

  • RecyclerView#setItemViewCacheSize(0)
  • recycledViewPool(NeverRecycleViewPool)

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

beeete2 avatar Jun 14 '19 07:06 beeete2

having a same issue

lee-heejin avatar Sep 25 '19 09:09 lee-heejin

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

Shusek avatar Nov 24 '22 13:11 Shusek