From 40c34f0606086577260576e243414629157b21df Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 18 May 2026 18:06:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=82=B9=E5=87=BB"=E4=BB=8A?= =?UTF-8?q?=E5=A4=A9"=E6=8C=89=E9=92=AE=E6=A0=87=E9=A2=98=E6=A0=8F?= =?UTF-8?q?=E6=8A=96=E5=8A=A8=EF=BC=9Aalpha=20=E6=B8=90=E5=8F=98=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=E6=9D=A1=E4=BB=B6=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 点击"今天"后 showToday 变为 false,按钮从布局移除导致 Row 高度 跳变 3px(85→82),引起标题栏抖动。改为始终保留按钮在布局中, 用 graphicsLayer alpha + animateFloatAsState 做淡入淡出动画, clickable(enabled) 控制可点击性,Row 高度不再变化。 Co-Authored-By: Claude Opus 4.7 --- .../kotlin/plus/rua/project/ui/MonthHeader.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt index 7a45a9b..04a636d 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt @@ -1,6 +1,7 @@ package plus.rua.project.ui import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutVertically @@ -18,6 +19,9 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.runtime.getValue +import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -83,14 +87,19 @@ fun MonthHeader( ) } Spacer(modifier = Modifier.weight(1f)) - if (showToday && onToday != null) { + val todayAlpha by animateFloatAsState( + targetValue = if (showToday && onToday != null) 1f else 0f, + animationSpec = tween(200) + ) + if (onToday != null) { Text( text = "今天", color = MaterialTheme.colorScheme.primary, fontSize = 14.sp, modifier = Modifier + .graphicsLayer { alpha = todayAlpha } .clip(RoundedCornerShape(12.dp)) - .clickable(onClick = onToday) + .clickable(enabled = showToday, onClick = onToday) .padding(horizontal = 10.dp, vertical = 4.dp) ) }