Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventHook + RecycledViewPool #1033

Open
smelfungus opened this issue May 16, 2022 · 3 comments
Open

EventHook + RecycledViewPool #1033

smelfungus opened this issue May 16, 2022 · 3 comments
Assignees

Comments

@smelfungus
Copy link
Sponsor

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
@smelfungus
Copy link
Sponsor Author

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.

@mikepenz
Copy link
Owner

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 mikepenz self-assigned this May 20, 2022
@smelfungus
Copy link
Sponsor Author

@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?

Repository owner deleted a comment from usandourkids525 Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants