Open ThomasArtProcessors opened 4 years ago
I think it is similar to #1025. See this as a workaround (not ideal for nested carousel) : https://github.com/airbnb/epoxy/issues/1025#issuecomment-733159885
I had to do a pretty heavy and inconvenient work around. First, I don't set the data in the databinding directly anymore. Instead I set it each time in onBind, and remove the adapter in onUnbind
onBind { model, view, position ->
val carousel = view.dataBinding.root
.findViewById<GroupCarousel>(R.id.carouselGroup)
carousel.setData(item, carouselScroll[item.id],
viewModel.shouldShowGroupTooltip())
view.setFullSpan(true)
}
onUnbind { model, view ->
val carousel = view.dataBinding.root
.findViewById<GroupCarousel>(R.id.carouselGroup)
carousel.cleanUp() // clean up to avoid memory leaks from Epoxy's Carousel
carouselScroll[item.id] = carousel.scrollData
if(carousel.hasScrolled) viewModel.hasSeenGroupTooltip()
}
You might notice the cleanUp
method, which is in the View itself, which extends Carousel.
In that view I do a few things:
I manually create a Controller and adapter if needed:
if (controller == null) {
controller = SimpleEpoxyController()
adapter = controller!!.adapter
[...]
And then I call that cleanUp method on onUnbind
fun cleanUp() {
clearOnScrollListeners()
controller?.cancelPendingModelBuild()
controller = null
swapAdapter(null, true)
}
That plus I do some manual calculations to remember the horizontal scroll of the Carousel which is otherwise lost. All in all not ideal but this fixed the memory leak and it properly remembers the horizontal position.
Hi there. I'm currently using epoxy a recyclerview that is hosting a set of views which I am creating directly via data binding.
groupCarousel is coming directly from a layout with databinding. I'm not using models directly nor am I using a controller directly, it's all done with databinding layouts and the
.withModels
The viewholder for groupCarousel looks like this:the GroupCarousel is a custom view extending epoxy's Carousel. In it I have a setData function that receives the data binding data set in the layout above. The function looks like this:
I have two issues: groupCarousel doesn't seem to remember its horizontal scroll position. But more importantly I get a memory leak, and I'm not sure how I could use the ol' trick of setting the adapter to null since those carousels are views inside the groupCarousel databinding model.
Here is the leak: