Recycler view losing state after Anvil.render()
gmarques33 opened this issue · 3 comments
Hi,
I noticed that after updating to Anvil 0.5.0, when I call Anvil.render() my RecyclerView loses its state.
The problem is that as the RecyclerView child are added by the adapter and not by the view method, on line: https://github.com/zserge/anvil/blob/master/anvil/src/main/java/trikita/anvil/Anvil.java#L315
our index is 0 and vg.getChildCount is not, so Anvil is removing all views from the RecyclerView.
This can happen with any view that uses adapters, RecyclerView, ViewPager etc.
As a workaround we could not remove views from RecyclerViews and ViewPagers, or we cold use some kind of attribute to tell Anvil that the view will be manipulated by an external adapter.
@gmarques33 That's interesting. I wonder how ListView works then..
There is a special method Anvil.skip()
that skips all the views created outside of Anvil. Perhaps it would make more sense to use skip()
+ end()
by default to ignore all non-Anvil views and remove only Anvil-made children.
@zserge ListView works because it is not a ViewGroup and RecyclerView is. So the RecyclerView is being treated as normal view group and processed by Anvil.
I'll take a look on Anvil.skip()
I'm not sure if it would be possible to use with current Anvil.skip()
. I've just updated my PR with a better implementation. Now I'm checking each child if it was created by Anvil before removing.