android 删除lazyColumn项后,可组合未拖动

ffscu2ro  于 2023-03-06  发布在  Android
关注(0)|答案(1)|浏览(158)

具有一个惰性列,通过从末尾向开始拖动该列上的项可以将其删除。当项未被删除但取代被删除项的项停止拖动时,该列处于拖动状态。

@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,但未拖动到已删除项的位置

qqrboqgw

qqrboqgw1#

问题解决,需要在itemindexed函数中添加密钥

相关问题