Swiping to remove items
In the previous sections, we learned how to present different composables for different data types. However, up until now, we have worked with a fixed list of items. What if you want to be able to remove items from the list? There are a few common mechanisms to achieve that – fixed Delete buttons on each item, swiping to delete, and long-clicking to select and then tapping a Delete button, to name a few. In this section, we will focus on the swiping to delete approach.
Let’s start by making our list mutable. If we replace listOf with mutableStateListOf and wrap it in a remember block, changes to our list would reflect on the UI. Our agent list should look like this:
val listItems = remember {
mutableStateListOf(
ListItemUiModel.GroupTitle("Current Employees"),
ListItemUiModel.Employee(...),
...