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

Kshitij Patil

12/01/2020, 7:24 AM
Can we mutate the items list being passed in to the
LazyColumnFor
? Like adding or removing items and expect the changes to be reflected in the
LazyColumn
? Something like
adapter.notifyDatasetChanged()
we used to do with
RecyclerView
t

Timo Drick

12/01/2020, 9:36 AM
Yes but you need to use:
Copy code
val list: SnapshotStateList<YouDataType> = mutableStateListOf()
When you change this list using add, remove, ... the UI will refresh automatically
k

Kshitij Patil

12/01/2020, 9:57 AM
Okay! So it'll just recompose that single add/remove right? Or it'll recompose the entire
LazyColumn
I'm concerned whether there are any performance hits by doing so?
t

Timo Drick

12/01/2020, 10:12 AM
I am not sure how exactly this is implemented in the LazyColumn/LazyRow. But currently this is the only way i am aware of to change the content dynamically without refreshing the complete list.
d

Dominaezzz

12/01/2020, 10:13 AM
I have used both and
SnapshotStateList
does granular updates,
State<List<...>>
does not.
7 Views