I'm trying to implement simple sort with items that are in a state.
This will work perfectly, only problem is that the animation is now gone, because it doesn't have a key.
LazyColumn(
state = listState,
) {
items(items.size) { index ->
val ticker = items[index]
Card(
modifier = Modifier
.fillMaxWidth()
.animateItemPlacement(), // This won't work
) {
Item(...)
}
}
}
But If I try to change it to:
items(items.size, key = { items[it].name }) { index ->
or If I use:
items(items, key = { items[it].name }) { item ->
It will have animations, but it will move items above and below current scroll position (even if you don't move). The wanted result is that you stay on top of the items, because we didn't move.
This is in a viewModel:
private val _state = MutableStateFlow<Response<List<Item>>>(Response.Loading)
val state get() = _state
private fun updateList() {
viewModelScope.launch(Dispatchers.IO) {
client.getItems()
.onSuccess {
unFilteredList = it.toMutableList()
val filteredList = filterList()
_tickerListState.value = Response.Success(filteredList)
}
.onFailure {}
}
}