Reputation: 25
I have been working for several days to solve a problem I have with recyclerView. I will not put the details as this is quite a "high" level question.
I have a RecyclerView with items in a certain order, and a Detail activity that allows to edit an item content. The content can change in a way the item order in the calling activity's RecyclerView can be changed.
I have a shared item transition to and from the Detail activity. The problem is that when I made a change that affect item order, the shared transition back to the RecyclerView item always goes to the previous item position, not to the new one.
To be short, I postpone the enter transition in the activity reenter, "wait" for the data change (if it hasn't already) using an adapter data observer, determine the new item position, scroll to that position and then start the postponed enter transition.
Debugging a logging it all, even the onMapSharedElements and the onCaptureSharedElementSnapshot, it seems that everything should be fine, but it is not. The effect is that the shared items animate to the previous position and then jump to the new one.
But I found a way to solve this, disable RecyclerView's item animator when I call the Detail and reenable it after the start postponed transition. It seems that item animator is faking / interfering with something with the shared transition.
The question is, which is the correct way to solve this?
Upvotes: 0
Views: 304
Reputation: 17922
In this case using startActivityForResult
with a result code and onActivityReenter
are methods to use.
When onActivityReenter
is invoked you can postpone the transition, re-order your items and then return the shared view to the new position.
Here's a working implemented example available for this use case.
Upvotes: 0