object with a title and body). When updating an object in my
ModelList
, my UI doesn't change. However, if I add an element to the list, or just re-assign the entire list after changes, then the UI updates. Is this behavior expected? What is the best way to manage changing objects within a list that are represented on a Jetpack Compose UI, like in a VerticalScroller or LazyColumnItems so that it actually updates?
a
Adam Powell
07/08/2020, 2:20 PM
The mutable object needs to back its mutable properties by
mutableStateOf
if you would like compose to see those changes
Adam Powell
07/08/2020, 2:20 PM
Other options include keeping the story object immutable and updating the list with a new changed copy
a
AJ
07/08/2020, 2:22 PM
Cool, the latter is what I've tried so far, I'll test out
mutableStateOf
a
Adam Powell
07/08/2020, 2:27 PM
If you're doing
myModelList[index] = object.copy(one = 1)
and that isn't causing recomposition, please file a bug as it should be seen as a structural change
👍 1
a
AJ
07/08/2020, 3:42 PM
Just to close the loop, I was only updating a property on my object. Using
copy
to change an object at a list index did work to update the UI, thanks for the help.