Hello,
First off thanks for a really nice library! I've been working with this library over that last few days and it's been a breeze. I currently hit a problem and would like to hear your point of view of it.
Imagine the following setup: Fragment A (with RecyclerView and Recycler obj) -> Fragment B (DetailFragment). Then using a shared element transition from Fragment A to Fragment B, for details how this is done see this article
Currently I create the Recycler object in onCreateView of Fragment A, because adopt need a RecyclerView instance. ( I hope this is correct? )
Once navigation from A -> B -> A happens the view of Fragment A will be destroyed and get created again when the user presses back. Along with the view the Recycler object will also be recreated due to it needing the newly created RecyclerView. This also means the adapter will be recreated but w/o it's old data. In order to make the transition to work one have to populate the Recycler object with the old data that was used before the view was destroyed. Normally the adapter would be created separately and this data would be retained inside and not recreated with the view.
How do we handle a new view being created with this library? Currently my workaround for this looks something along the ways like this:
private lateinit var recycler: Recycler<DevicesRow>
private var data = emptyList<ItemRow>().toDataSource()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = AFragmentBinding.inflate(inflater)
val recyclerView = binding.recyclerView
recycler = Recycler.adopt(recyclerView) {
...
}
recycler.data = data
postponeEnterTransition()
rv.doOnPreDraw {
startPostponedEnterTransition()
}
}
override fun onDestroyView() {
super.onDestroyView()
data = recycler.data
}
override fun onResume() {
// I'm starting to observe my presenter here
}
override fun onPause() {
// Stopping to observe my presenter here
}
Worth noting is that onResume() won't be called unless startPostponedEnterTransition() is called first in onCreateView() or onViewCreated(), if we want the animation to work the adapter also needs to have the data when it is called. The solution works for now, but it doesn't really feel like it is the optimal way to recreate the entire Recycler object along with the view?
Hello,
First off thanks for a really nice library! I've been working with this library over that last few days and it's been a breeze. I currently hit a problem and would like to hear your point of view of it.
Imagine the following setup: Fragment A (with RecyclerView and Recycler obj) -> Fragment B (DetailFragment). Then using a shared element transition from Fragment A to Fragment B, for details how this is done see this article
Currently I create the Recycler object in
onCreateViewof Fragment A, because adopt need a RecyclerView instance. ( I hope this is correct? )Once navigation from A -> B -> A happens the view of Fragment A will be destroyed and get created again when the user presses back. Along with the view the Recycler object will also be recreated due to it needing the newly created RecyclerView. This also means the adapter will be recreated but w/o it's old data. In order to make the transition to work one have to populate the
Recyclerobject with the old data that was used before the view was destroyed. Normally the adapter would be created separately and this data would be retained inside and not recreated with the view.How do we handle a new view being created with this library? Currently my workaround for this looks something along the ways like this:
Worth noting is that
onResume()won't be called unlessstartPostponedEnterTransition()is called first inonCreateView()oronViewCreated(), if we want the animation to work the adapter also needs to have the data when it is called. The solution works for now, but it doesn't really feel like it is the optimal way to recreate the entireRecyclerobject along with the view?