Epoxy attribute fields on a model cannot be changed once the model is added to a controller. Check that these fields are not updated, or that the assigned objects are not mutated, outside of the buildModels method. The only exception is if the change is made inside an Interceptor callback. Consider using an interceptor if you need to change a model after it is added to the controller and before it is set on the adapter. If the model is already set on the adapter then you must call `requestModelBuild` instead to recreate all models.
i did everything and this issue still existing, any idea?
Please, does anyone faced this issue???
You can't change of of any variable on bind method on controller class.
What's the issue to begin with? What are you trying to accomplish?
The error message is quite self-descriptive, and it's telling you that you aren't supposed to mutate nor update models manually after they were added to the controller, but instead either use an interceptor or call requestModelBuild (which will diff and update the specific model that changed for you).
@mradzinski I am also facing this issue and I am using requestModelBuild() function after updating item at position 0. If this is not correct way then can anyone here tell what is the best way to update any item and notifying epoxyrecyclerview. I am using kotlin databinding
I would love to see a use case of using an "interceptor", the docs do not say much about it.
i found the solution. the data that you added to epoxyModel_. you have not to modify directly. so, if you use kotlin, you can create new reference of that model and requestModelBuild() again.
to create new reference, you can use copy() or if it is the collection, use toMutableList() / toList()
for example, inside EpoxyController:
var myModel: MutableList<WhateverModel> = mutableListOf()
override fun buildModels() {
myModel.forEach {
MyEpoxyModel_()
.id(R.id.epoxid)
.whateverModel(it)
.onBind { model, view, position ->
view.cardView.setOnClickListener {
val modelCopy = model.whateverModel.copy()
modelCopy.anyAttr = "this is what i changed"
val index = myModel.indexOf(model.whateverModel)
myModel[index] = modelCopy
requestModelBuild()
}
}
.addTo(this)
}
}
i have a social feed screen in my project that i used epoxy for listing posts. users can like or unlike posts. i'm facing this issue when the new posts are added to pagingcontroller.
is there any way?
I was facing the same issue yesterday. Now I managed to solve it.
TL;DR The data for epoxy have to be different with the data source.
So, what I do is:
- Create source data and store in ViewModel.
- Create a copy of source data every time epoxy requestModelBuild()
- When I want to change the data of an item, I call the function in ViewModel to make change on the source data.
- call epoxy recyclerview to requestModelBuild
Update your Model(Data class) and submit data, this will update the item that you want to update.
override fun buildModels() {
UserModel_()
.id(user.id)
.name(user.name)
.onClickListener { model, parentView, clickedView, position ->
user.name = "New updated name"
setData(user)
}
.addTo(this)
}
@jimale Can you share a sample?
In my case, I changed the priority that flag by @EpoxyAttribute when the bind holder run. so i try to new a local object copy from origin priority ,and render view use local object . wish this help you