0

I'm trying to wrap my head around implementation of shared view transitions between fragments

The challenge is coming from the MVVP restricitons:

  • Adapter of RecycleView has knowledge of selected element and view attached via callback from View
  • Adapter is passing information about click to ViewModel stripping out all information about view, as it can't hold it. That's because of rule - no android imports in ViewModel except of *arch
  • ViewModel sends event to Fragment to open another Fragment
  • At this point Fragment doesn't know what view to use to start transition in .addSharedElement(..)

How to address this issue?

I was thinking about saving reference to clicked View inside Fragment instance but it looks like a cheating

Any ideas and suggestions are very welcome

ruX
  • 7,224
  • 3
  • 39
  • 33
  • How about passing a position from `ViewModel` to `Fragment`. Based on that position you can get a `view` from `LayoutManager` – Demigod Jun 29 '18 at 13:03
  • @Demigod it could be a solution but there is a corner case when view can be already recycled or represent another entity. Do you have examples how to access view via `LayoutManager` based on the index of element in adapter? – ruX Jun 30 '18 at 12:55
  • sure it can be done as described here https://stackoverflow.com/a/33798938/3569545 – Demigod Jun 30 '18 at 20:31

0 Answers0