In your example, you keep an additional list for deleted items. However, i suspect in most apps, you would want to modifiy the existing data model and remove items from it upon deletion.
To achieve this, I'm currently setting the visibility to false when clicking on the delete button (or swiping, whatever you use) and then using a LaunchedEffect with delay to delete the item from the model.
I get an enter transition on the next element in the list then, however...
Code:
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun ItemRow(
item:Any,
deleteItem: (Any) -> Unit
) {
var visibility by remember(item) {mutableStateOf(true)}
if (!visibility) {
LaunchedEffect(subject = item) {
delay(500)
deleteItem(item)
}
}
AnimatedVisibility(visible = visibility,
enter = fadeIn(initialAlpha = 1f), // fake no animation
exit = shrinkVertically(animSpec = tween(durationMillis = 500)) + fadeOut()
) {
/** Row content with delete handler, onDelete = {visibility = false} **/
}
}
Is there currently a better solution for this?