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

Is there a way to find first visible item's EpoxyHolder? #952

Closed
littledot opened this issue Apr 27, 2020 · 2 comments
Closed

Is there a way to find first visible item's EpoxyHolder? #952

littledot opened this issue Apr 27, 2020 · 2 comments

Comments

@littledot
Copy link
Contributor

littledot commented Apr 27, 2020

I would like to animate Views when an event (not initiated by the user) occurs. (If the event was initiated by the user, I could use OnModelClickListeners to obtain the clicked EpoxyHolders. But not for this case.)

Previously, I would use LayoutManager.findFirstVisisbleItem() & RecyclerView.findViewHolderForAdapterPosition() to query the ViewHolder I would like to animate, then set up my animators.

However, I could not find a way to link a RecyclerView.ViewHolder to a EpoxyModelWithHolder. Does Epoxy provide any way to find the first visible item position's EpoxyHolder?

Thanks

@littledot
Copy link
Contributor Author

After some digging, RecyclerView.findViewHolderForAdapterPosition() returns a EpoxyViewHolder, which references the data in epoxyModel and the views in epoxyHolder. This is just what I needed!

However, the epoxyModel has a public getter while epoxyHolder does not provide any public accessors. Considering that RecyclerView.ViewHolder.itemView is completely public, which is intended to let users directly reference the RecyclerView's items' Views, would it not make sense to at least expose a public getter for EpoxyViewHolder.epoxyHolder? This will allow users to reference EpoxyModelWithHolder from a RecyclerView.ViewHolder.

@elihart
Copy link
Contributor

elihart commented May 5, 2020

I think generally the approach you should take to do this is to toggle a prop on the model, have the model do a partial rebind and have that trigger the animation. this keeps the animation logic completely inside of the model/holder. i'll merge the PR though if you really need to do it that way

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