https://kotlinlang.org logo
#android
Title
# android
f

faisalahmed

03/10/2023, 11:20 AM
Hi folks, a question about
mutableStateListOf()
. add and remove on the list triggers succesful recompositions of the specific item, but changing the value at any index of this list does not trigger any recomposition. Been scratching my head at this. My
LazyColumn
is keyed to a unique
id
coming in the data as well. So I am wondering what might be going wrong. Following is an example. Inside
ViewModel
Copy code
val list = mutableStateListOf<Messages>()

fun onMessageChanged(newMessage: Message) {
  val index = list.indexOf(newMessage) // returns correct index
  list[index] = newMessage // does not trigger recomposition
}
g

George Mulligan

03/10/2023, 3:25 PM
This looks like it is effectively setting newMessage[index] to the same value already there. Since the list itself is not actually changing a recomposition is likely not triggered. If you set the value at the index to a different value is a recomposition triggered?
5 Views