https://kotlinlang.org logo
#compose
Title
# compose
t

Travis Griggs

11/09/2023, 8:05 PM
Sigh. Sometimes, I think I'm "getting it" and then... I don't. This code behaves as desired (the list grows as scans are added to the scanList.scans via a "launched flow computation"
Copy code
LazyColumn(modifier = Modifier.weight(1f)) {
	scanList.scans.forEach { result -> 
		item(key = result.device.id) {
			Text(text = "${result.device.name}")
		}
	}
}
But this block, seeming very similar, does not update visually:
Copy code
LazyColumn(modifier = Modifier.weight(1f)) {
   items(items = scanList.scans, key = { result -> result.device.id }) { result ->
      Text(text = "${result.device.name}")
   }
}
I am scratching my head why. Is there some sort of tool, that I can fire up my UI and then see what the dependencies that are going to cause a recomposition are?
m

mkrussel

11/09/2023, 8:18 PM
My guess would be it is related to how scans is added to scanList. Is scans pointing to a MutableCollection that is being updated and assigned to a new instance of scanList? I think that will cause trouble with passing that list to a function like items where it detects that it did not change because the list itself changed so the list in the previous call is equal the list in the new call.
t

Travis Griggs

11/09/2023, 8:40 PM
Copy code
class ScanList {
   var scans by mutableStateOf<List<ScanResult>>(emptyList())
...
(It was mutableStateList, but changing it was one of the dart throws that didn't work). Either way, it flattens/extracts the value in both cases via scanList.scans. But one works, one does not.
m

mkrussel

11/09/2023, 8:42 PM
I agree that this should work.
s

shikasd

11/09/2023, 8:47 PM
Both should work from my perspective, please file a bug with complete example 🙂
3 Views