Skip to content

Instantly share code, notes, and snippets.

@hieuwu
Created February 19, 2023 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hieuwu/bdd173058082406977118f4afd3c77c6 to your computer and use it in GitHub Desktop.
Save hieuwu/bdd173058082406977118f4afd3c77c6 to your computer and use it in GitHub Desktop.
Swipe to delete item wrapper
val state = rememberDismissState(
confirmStateChange = {
if (it == DismissValue.DismissedToStart) {
viewModel.onRemoveTag(item)
}
true
}
)
SwipeToDismiss(
state = state,
background = {
val color by animateColorAsState(
targetValue = when (state.dismissDirection) {
DismissDirection.StartToEnd -> MaterialTheme.colorScheme.primary
DismissDirection.EndToStart -> MaterialTheme.colorScheme.primary.copy(
alpha = 0.2f
)
null -> Color.Transparent
}
)
Box(
modifier = modifier
.fillMaxSize()
.background(color = color)
.padding(10.dp),
) {
Icon(
imageVector = Icons.Filled.Delete,
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
modifier = modifier.align(Alignment.CenterEnd)
)
}
},
dismissContent = {
TagItem(tag = item, onEditTag = {
selectedName = item.name
viewModel.onEditTag(tag = item)
bottomSheetScaffoldState.bottomSheetState.expandOrCollapse(
coroutineScope
)
})
},
directions = setOf(DismissDirection.EndToStart),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment