我正在使用Jetpack Compose中的SwipeToDismiss
从列表中删除项目。问题是,每当你滑动一个项目时,它会删除滑动的项目,但滑动的屏幕不会消失。
此图像显示了问题。
它将覆盖其下方的项目。
下面是我的SwipeToDismiss代码
val dismissState = rememberDismissState(
confirmStateChange = {
if (it == DismissValue.DismissedToStart) {
storedItemsViewModel.deleteOne(sentence)
}
true
}
)
val direction = dismissState.dismissDirection
SwipeToDismiss(
state = dismissState,
/*** create dismiss alert Background */
directions = setOf(
DismissDirection.EndToStart
),
dismissThresholds = { /*direction ->*/
FractionalThreshold(if (direction == DismissDirection.EndToStart) 0.1f else 0.5f)
FractionalThreshold(0.2f)
},
background = {
val color = when (dismissState.dismissDirection) {
DismissDirection.StartToEnd -> Color.Green
DismissDirection.EndToStart -> Color.Red
null -> Color.Transparent
}
val alignment = Alignment.CenterEnd
val icon = Icons.Default.Delete
val scale by animateFloatAsState(
//this scales the icon
if (dismissState.targetValue == DismissValue.Default) 0.75f else 1f
)
Box(
Modifier
.fillMaxSize()
.background(color)
.padding(horizontal = Dp(20f)),
contentAlignment = alignment
) {
Icon(
icon,
contentDescription = "Delete Icon",
modifier = Modifier.scale(scale)
)
}
},
/**** Dismiss Content */
dismissContent = {
Card(elevation = animateDpAsState( if (dismissState.dismissDirection != null) 4.dp else 0.dp).value) {
FavoriteItem(sentence, word, grammar)
}
},
)
1条答案
按热度按时间8i9zcol21#
您必须为lazyItems提供唯一的密钥。
...