具有一个惰性列,通过从末尾向开始拖动该列上的项可以将其删除。当项未被删除但取代被删除项的项停止拖动时,该列处于拖动状态。
@Composable
fun DraggableCardComplex(
isRevealed: Boolean = false,
product: order, onClick: () -> Unit,
offset: Float = CARD_OFFSET,
onExpand: () -> Unit,
onCollapse: () -> Unit,
) {
val offset = remember {
mutableStateOf(0f)
}
val transitionState = remember {
MutableTransitionState(isRevealed).apply {
targetState = isRevealed
}
}
val transition = updateTransition(transitionState, "cardTransition")
val offsetTransition by transition.animateFloat(
label = "cardOffsetTransition",
transitionSpec = { tween(durationMillis = ANIMATION_DURATION) },
targetValueByState = { if (isRevealed) offset + offsetX.value else -offsetX.value },
)
Card(
modifier = Modifier
.wrapContentSize()
.fillMaxWidth()
.offset { IntOffset((offsetX.value + offsetTransition).roundToInt(), 0) }
.pointerInput(Unit) {
detectHorizontalDragGestures { change, dragAmount ->
change.consumeAllChanges()
val original = Offset(offsetX.value, 0f)
val summed = original + Offset(x = dragAmount, y = 0f)
val newValue = Offset(x = summed.x.coerceIn(offset, 0f), y = 0f)
if (newValue.x < 0) {
offsetX.value = 0f
onExpand()
return@detectHorizontalDragGestures
} else if (newValue.x <= 0) {
offsetX.value = 0f
onCollapse()
return@detectHorizontalDragGestures
}
offsetX.value = newValue.x
}
},
shape = remember {
RoundedCornerShape(0.dp)
},
content = { item(product, onClick) }
)
}
项的isRelvead bool为false,但未拖动到已删除项的位置
1条答案
按热度按时间qqrboqgw1#
问题解决,需要在itemindexed函数中添加密钥