mikepenz/FastAdapter

EventHook + RecycledViewPool

smelfungus opened this issue · 3 comments

About this issue

Hello! I've recently started to combine a series of consecutive Fragment RecyclerViews with RecycledViewPool to bump performance up via View pooling. However, it seems like that does not work too well with the FastAdapter EventHook mechanism (onPostCreateViewHolder is no longer called for "pooled" Views from following Fragments, old, no-longer-valid hooks are being reused (because of tag-based attachment?))
Any ideas on how to properly manage that case?

Best regards,
Illia

Details

  • Used library version 5.6.0

The "Reused" hook itself is working right, and the item is correct, too. However, reused hook contains a reference to old, no-longer-valid Fragment, old Fragment contains a reference to old, no-longer-valid stateful ViewModel, and so on...
Maybe there's a way to implement an optional FastAdapter mode to bind hooks with ViewHolder bind event instead of a creation-based "hooking"? Probably it may impact performance tho.

Given this usecase? Would a "quick" fix be to offer an API to remove previously registered event hooks?

EventHooks are kept within the FastAdapter instance, so it sounds you re-use the FastAdapter class over multiple Fragments?
Or actually more indirectly via the adapter being kept inside the item view's tag:

val tagAdapter = viewHolder.itemView.getTag(R.id.fastadapter_item_adapter)
val adapter = tagAdapter as? FastAdapter<Item> ?: return@setOnClickListener

So practically you need to clear tags from itemView when such caching is setup. Do you have any way to clear the tags of a view when re-used from the RecycledViewPool?

@mikepenz, thank you for getting back to me! Yes, so FastAdapters are not reused, but item views are reused via RecycledViewPool, which indirectly causes Views to keep hooks and attach them only once (from the very first fragment) via tags during initial VH creation.
Potentially we can clear tags during the bind, but then we should somehow re-attach new event hooks after it...
Maybe that's just a unique usecase that should not have FastAdapter support, and we should just pass new listeners to items and set them in a bind each time, but I'm just wondering what are your thoughts on some sort of a bind-based hooks attachment or API?