In my project I have an expandable recycler view. Almost everything is working properly.
When I expand the view I have a chevron, that I want to perform a 180º rotation and vice versa for the collapsing animation.
I'm using this function to do the rotation view.animate().rotation(180f) for one of the states and for the other I pass 0 to the rotation function.
The icon is rotated the first time with the animation. My problem now is that, the second time I call submitList(List<UIModel>) it doesn't perform the animation itself, but the icon blinks into the 180º state.
One important note is that I'm using MVI, and I added a click listener to the ViewHolder, which is simply a callback for the Fragment, that will pass this info to the ViewModel. The ViewModel will update its state to have that list item as expanded and then submit the list.
Rotation animation works perfectly, if I call the function mentioned above right in the click listener, without calling the submitList() function.
As a summary, this is flow (first time 8th step doesn't apply, and it works properly with the animation):
- User clicks on chevron;
- callback is called;
- fragment notifies view model;
- view model updates state;
- fragment is notified that there are changes;
- fragment submits list calling (
submitList()); onBindViewHolderis called, and I perform the rotation animation according to the UIModelisExpandedvariable.- rotation is applied, but without any animation, just a flick between both position
Two wild guesses:
Is the rotation value part of the
DiffUtil.Callback? (the value or something to indicate that the item changed).Did you try for the sake of Android to replace
view.animate().rotation(180f)with something more silly like:This would perform your animation inside the next rendering frame; I have a suspicion the animation is getting buried there and the final state is shown (the thing rotated already).