How to handle return transition with shared elements?
<p>I want to implement a custom <code>Pre-Lollipop</code> transition. I have a shared element in both activities(<code>A</code> and <code>B</code>), that is a simple <code>ImageView</code>. My custom transitions with shared elements work by the same principle as <code>native</code> transitions do. First of all, I set the background of <code>B</code> activity to transparent, then I capture the start state of the shared element and pass this data to <code>B</code> activity. In <code>B</code> I capture the end state of the shared view and create an <code>Animator</code> that will animate the view between the two states, of course that animation happens in <code>B</code> activity.<br/></p>

<p>At this point, as long as I have the same shared element in both activities everything is perfect, and I'm able to apply appropriate return transition. However, when I want to implement some kind of gallery(when you can slide images to the left and right in <code>B</code> activity) I have a problem with return transition. In this case, both activities share the same source of data, so the user can simply change the shared element in <code>B</code> activity. So, what if I change that shared element in the second activity? Then, obviously, in order to implement return transition I need to know the size and position of that element in <code>A</code> activity, right?<br/></p>

<p>Basically, we have only <code>2</code> scenarios (correct me, if I'm wrong) to do so:</p>

<ul>
<li>Pass the state of that shared element from <code>B</code> to <code>A</code> activity using <code>onActivityResult</code> callback, and apply the return animation in <code>A</code>.</li>
<li>Somehow get the properties of the shared element from <code>A</code> activity and implement the return animation in <code>B</code>.</li>
</ul>

<p>Moreover, I also have to redraw a <code>RecyclerView</code> or whatever that keeps the data using <code>requestLayout()</code> or <code>invalidate()</code> method.</p>

<p>I know that I can implement all this stuff with <code>native</code> transitions using <code>SharedElementCallback</code> callback and <code>onActivityReenter()</code> method. This framework somehow handles to apply this return transition in the called activity not in the caller.</p>

<p>So, I'm wondering if there is any alternative?</p>