Hi everyone. I am issuing one funky stuff with Sta...
# compose
n
Hi everyone. I am issuing one funky stuff with State and LazyColumn. Basically updating list item does not make the UI update right away but only after scrolling.
Copy code
@Composable
fun Test() {
  var items by remember {
    mutableStateOf(
      mutableListOf(
        1,
        2,
        3,
      )
    )
  }

  LazyColumn {
    items(items) {
      Box(
        modifier = Modifier
          .fillMaxWidth()
          .height(100.dp)
          .clickable {
            val list = items
            list[0] = 6
            items = list // this does not make the list to recompose
            items = mutableListOf(6,2,3) // this does not work either
            items = mutableListOf(6,3,2) // this makes the list to recompose
          },
        contentAlignment = Alignment.Center,
      ) {
        Text(text = it.toString(), fontSize = 50.sp)
      }
    }
  }
}
If you know why or got an idea please let me know. P.S. Compose version is
1.0.0-beta02
a
Does it help if you change
mutableListOf
to
mutableStateListOf
?
a
possibly related to the issues fixed by https://android-review.googlesource.com/c/platform/frameworks/support/+/1640311 which should be released in beta03 next week
but yes, I suspect if you change
items
to be an immutable reference to a
mutableStateListOf
then you'll be back in business for now
i.e.
Copy code
val items by remember { mutableStateListOf(1, 2, 3) }
which means you won't be able to reassign
items
in the click listener, but editing its contents should be reflected as expected.
n
@aiidziis @Adam Powell yes using mutableStateListOf let’s me to update content and it is working. Thank you 👍
👍 1
🙌🏻 1