Closed eboudrant closed 5 years ago
Thanks for the report, I think this has existed for a long time. It will only happen if you use the model click listener.
The code in WrappedEpoxyModelClickListener does
@Override
public void onClick(View v) {
EpoxyViewHolder epoxyHolder = getEpoxyHolderForChildView(v);
if (epoxyHolder == null) {
throw new IllegalStateException("Could not find RecyclerView holder for clicked view");
}
final int adapterPosition = epoxyHolder.getAdapterPosition();
if (adapterPosition != RecyclerView.NO_POSITION) {
//noinspection unchecked
originalClickListener
.onClick((T) epoxyHolder.getModel(), (V) epoxyHolder.objectToBind(), v, adapterPosition);
}
}
which assumes that the top level view/model should be used. It needs to be updated to check for group handling somehow.
I will try to look into it soon, unless someone else can take it
Potentially the generated code needs to change the WrappedEpoxyModelClickListener
constructor to also take the model it is associated with, then when we find a model group we can check whether the listener's model is the top level group, or any nested models (potentially recursively)
Any update on this?
No, but I'd love to see somebody put up a PR.
It may be as simple as modifying WrappedEpoxyModelClickListener
to check if the top level view holder model is a group and if so pulling out the right child model
We've started using MvRx and Epoxy for a new app we're building here at work, and the libraries are great, but I just recently received an feature request that requires a fairly complicated UI design for rows, which has required me to use an EpoxyModelGroup. We are using databindings so I've added the clickListener in the xml. This has caused me to run into this ClassCastException error as well, so I wanted to check and see if there is a fix in the works for this, or should I avoid using the model onClickListener?
Thanks for the reminder, just fixed it finally https://github.com/airbnb/epoxy/pull/767
Oh wow! Awesome. Thank you so much for the quick reply and fix. I really appreciate it.
I am not sure it is a new or old issue but when we set a click listener on an
EpoxyModel
which is part of anEpoxyModelGroup
we receiveClassCastException
on click :