From 877a3f9aa4739126efc620a38b9849376e04aaa2 Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 1 Jun 2026 17:15:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=97=A5=E6=9C=9F=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=99=A8=E6=BB=91=E5=8A=A8=E5=88=A0=E9=99=A4=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8A=A8=E7=94=BB=E7=AD=89=E5=BE=85=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E7=A7=BB=E9=99=A4=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plus/rua/project/ui/DateCheckerScreen.kt | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/core/src/main/kotlin/plus/rua/project/ui/DateCheckerScreen.kt b/core/src/main/kotlin/plus/rua/project/ui/DateCheckerScreen.kt index b811dc7..6820c6d 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/DateCheckerScreen.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/DateCheckerScreen.kt @@ -131,6 +131,7 @@ fun DateCheckerScreen(onBack: () -> Unit, modifier: Modifier = Modifier) { ) } var nextId by remember { mutableIntStateOf(3) } + var pendingDeleteIds by remember { mutableStateOf(setOf()) } var showDatePicker by remember { mutableStateOf(false) } var datePickerTarget by remember { mutableStateOf(null) } @@ -233,37 +234,39 @@ fun DateCheckerScreen(onBack: () -> Unit, modifier: Modifier = Modifier) { .padding(horizontal = 16.dp, vertical = 4.dp) ) { rows.forEachIndexed { index, row -> - val expiryDate = row.days?.let { productionDate.plus(DatePeriod(days = it)) } - val daysRemaining = expiryDate?.let { today.daysUntil(it) } - val status = when { - daysRemaining == null -> ExpiryStatus.UNKNOWN - daysRemaining < 0 -> ExpiryStatus.EXPIRED - daysRemaining == 0 -> ExpiryStatus.URGENT - daysRemaining <= 7 -> ExpiryStatus.URGENT - daysRemaining <= 30 -> ExpiryStatus.WARNING - else -> ExpiryStatus.SAFE - } - - val dismissState = rememberSwipeToDismissBoxState( - confirmValueChange = { value -> - if (value == SwipeToDismissBoxValue.EndToStart) { - rows = rows.filter { it.id != row.id } - true - } else { - false - } - } - ) + val isBeingDeleted = row.id in pendingDeleteIds key(row.id) { + val dismissState = rememberSwipeToDismissBoxState( + confirmValueChange = { value -> + if (value == SwipeToDismissBoxValue.EndToStart) { + pendingDeleteIds = pendingDeleteIds + row.id + true + } else { + false + } + } + ) + var visible by remember { mutableStateOf(false) } androidx.compose.runtime.LaunchedEffect(Unit) { visible = true } + val expiryDate = row.days?.let { productionDate.plus(DatePeriod(days = it)) } + val daysRemaining = expiryDate?.let { today.daysUntil(it) } + val status = when { + daysRemaining == null -> ExpiryStatus.UNKNOWN + daysRemaining < 0 -> ExpiryStatus.EXPIRED + daysRemaining == 0 -> ExpiryStatus.URGENT + daysRemaining <= 7 -> ExpiryStatus.URGENT + daysRemaining <= 30 -> ExpiryStatus.WARNING + else -> ExpiryStatus.SAFE + } + AnimatedVisibility( - visible = visible, + visible = visible && !isBeingDeleted, enter = expandVertically( expandFrom = Alignment.Bottom, animationSpec = androidx.compose.animation.core.spring( @@ -314,6 +317,14 @@ fun DateCheckerScreen(onBack: () -> Unit, modifier: Modifier = Modifier) { ) } } + + if (isBeingDeleted) { + androidx.compose.runtime.LaunchedEffect(row.id) { + delay(400) + rows = rows.filter { it.id != row.id } + pendingDeleteIds = pendingDeleteIds - row.id + } + } } if (index < rows.lastIndex) {