From 780a5e70dd6bbb6df77eb64fa9dae214c92addc4 Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 18 May 2026 18:20:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=98=E5=8F=A0=E6=80=81?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=B9=B4=E8=A7=86=E5=9B=BE=EF=BC=9A=E5=85=88?= =?UTF-8?q?=E5=B1=95=E5=BC=80=E5=86=8D=E5=88=87=E6=8D=A2=20+=20AnimatedCon?= =?UTF-8?q?tent=20=E5=B0=BA=E5=AF=B8=E7=9E=AC=E5=88=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 折叠态下 toggleYearView 不再直接 return,而是先动画展开回月视图再进入年视图; MonthHeader 的 AnimatedContent 添加 SizeTransform(snap()) 避免内容切换时尺寸动画; 清理未使用的 import。 Co-Authored-By: Claude Opus 4.7 --- .../kotlin/plus/rua/project/CalendarViewModel.kt | 8 +++++++- .../kotlin/plus/rua/project/ui/CalendarMonthView.kt | 1 - .../commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt | 9 +++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt b/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt index 9bd6179..eeb795a 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt @@ -112,9 +112,15 @@ class CalendarViewModel( * 当前视图被直接移除;动画只作用在目标视图的 scale/alpha 上。 */ fun toggleYearView() { - if (isCollapsed) return yearViewJob?.cancel() yearViewJob = coroutineScope.launch { + // 折叠态先展开回月视图,再切换年视图 + if (isCollapsed) { + _collapseAnimatable.animateTo( + 0f, spring(dampingRatio = 0.8f, stiffness = 400f) + ) + isCollapsed = false + } if (isYearView) { // 年 → 月:先启动动画(年视图开始淡出),等一帧后翻转 isYearView(月视图开始组合) composeTraceBeginSection("YearView→MonthView") diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt index 3147918..324015d 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -36,7 +36,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.withFrameNanos import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshotFlow 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 04a636d..5064371 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt @@ -1,7 +1,9 @@ package plus.rua.project.ui import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.SizeTransform import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.animation.core.snap import androidx.compose.animation.core.tween import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutVertically @@ -16,12 +18,11 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue 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 @@ -59,7 +60,7 @@ fun MonthHeader( } else { slideInVertically(tween(250)) { it } togetherWith slideOutVertically(tween(250)) { -it } - } + } using SizeTransform { _, _ -> snap() } } ) { (y, m) -> Text( @@ -77,7 +78,7 @@ fun MonthHeader( } else { slideInVertically(tween(250)) { it } togetherWith slideOutVertically(tween(250)) { -it } - } + } using SizeTransform { _, _ -> snap() } }, modifier = Modifier ) { week ->