so I have a LazyColumn, with `items`, and when something happens to one of the items’ onClick (defin...
o
so I have a LazyColumn, with
items
, and when something happens to one of the items’ onClick (defined in itemContent), I want the
items
value to change, the list to be shuffled, re-ordered, etc.. how can I do that ?
it needs to be a mutablestate, the list of items
yeap
j
You can use ViewModel to handle this. In yout viewmodel, create a method to shuffle the list, then, send again to lazycolumn, and it will recompose and change your items. To get smooth change, just add in your item layout (inside lazycolumn)
Modifier.animateItemPlacement()
o
yea already done
thanks for the suggestion
didn’t really have to resort to viewModel, I just did
.sortedBy{ it.status = Status.Enabled }
that automatically recomposes
j
Its not good for the performance, if you are using directly in compose, use like that:
val items = remember { yourList.sortedBy{ it.status = Status.Enabled } }
m
why not good for the performance @Jhonatan Sabadi?
o
Cause you don’t want it to recompose every single time
It’s right
m
I meant how?
o
By remembering it through recompositions
Not having to recalculate it
I think
j
That's It. Every change in your compose, would cause recomposition in lazy lazyout. And that not good for performance, you can check it com Layout Inspector, to see recomposition count