Sterling Albury
11/30/2023, 7:18 PMfun Modifier.foo(
fooList: List<Foo>
): Modifier = this.then(
FooModifierElement(fooList)
)
my composable content:
var fooList by mutableStateOf(mutableListOf<Foo>())
setContent {
CustomComposable(modifier = Modifier.foo(fooList))
}
if I just add something to the list, nothing happens, but if I assign fooList
to a new list instance, then it recomposes. Is there a way to be able to just update the list and trigger a recomposition?Alexander Maryanovsky
11/30/2023, 7:22 PMAlexander Maryanovsky
11/30/2023, 7:23 PMSnapshotStateList
Alexander Maryanovsky
11/30/2023, 7:23 PMSnapshotStateList
notifies the composition whenever any of its values changes.Sterling Albury
11/30/2023, 7:31 PMSterling Albury
11/30/2023, 7:45 PMmutableStateListOf
but don’t see the recompositions.Alexander Maryanovsky
11/30/2023, 7:49 PM@Composable
fun Items(list: List<Int>) {
Column {
for (item in list) {
Text(item.toString())
}
}
}
setContent {
val list = remember { mutableStateListOf(0) }
Column {
Button(onClick = { list.add(list.size) }){
Text("Click me")
}
Items(list)
}
}
Sterling Albury
11/30/2023, 8:12 PMsetContent
so I’m not able to use remember
…maybe this is part of my problemAlexander Maryanovsky
11/30/2023, 8:14 PM@Composable
fun Items(list: List<Int>) {
Column {
for (item in list) {
Text(item.toString())
}
}
}
val list = mutableStateListOf(0)
@Composable
fun App() {
Column {
Button(onClick = { list.add(list.size) }){
Text("Click me")
}
Items(list)
}
}
Sterling Albury
11/30/2023, 8:18 PMZach Klippenstein (he/him) [MOD]
12/01/2023, 12:01 AMModifier.foo
factory functions, many of the Modifier.Node
interfaces don’t observe snapshot reads, so you will need to wire that up yourself.