From 20425e392c31253d53ba9cdd0d89adbffdf1da2c Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 26 May 2026 17:39:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=81=A2=E5=A4=8D=E6=8A=98=E5=8F=A0?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=20Phase=202=20=E4=B8=8B=E6=96=B9=E8=A1=8C?= =?UTF-8?q?=E5=81=8F=E7=A7=BB=EF=BC=8C=E7=A7=BB=E9=99=A4=20showWeekPager?= =?UTF-8?q?=20=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 恢复 CalendarMonthPage 中 isBelow 行的 `- phase2 * belowRowsHeight` (2592a5f 误删导致展开时下方行原地淡入而非滑出) - 移除 CalendarMonthView 的 showWeekPager + AnimatedContent 切换 (完全折叠后下拉拖拽时只显示 WeekPager 单周,上下空白) - 回退到始终显示 CalendarPager,由 CalendarMonthPage 处理折叠动画 - 添加详细动画调试日志(Page/WeekRow/View 三层) Co-Authored-By: Claude Opus 4.7 (1M context) --- .../plus/rua/project/ui/CalendarMonthPage.kt | 27 ++++++- .../plus/rua/project/ui/CalendarMonthView.kt | 80 +++++-------------- 2 files changed, 41 insertions(+), 66 deletions(-) diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt index b4629ad..d43d1dc 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt @@ -106,6 +106,17 @@ fun CalendarMonthPage( val anchorIndex = remember(year, month, selectedDate) { weeks.indexOfFirst { week -> week.any { it.date == selectedDate } } } + + // 全局动画参数日志(每次重组) + val pageFrameNs = System.nanoTime() + Log.d( + TAG_CMP, + "Page[$year-$month]: anchorIndex=$anchorIndex weeksSize=${weeks.size} " + + "phase1End=${if (anchorIndex > 0 && weeks.size > 1) anchorIndex.toFloat() / (weeks.size - 1) else 0f} " + + "effectiveWeeks=$effectiveWeeks rowHeightPx=$rowHeightPx " + + "collapseProgress=$collapseProgress frameNs=$pageFrameNs" + ) + val totalHeightDp = if (rowHeightPx > 0) { val h = rowHeightPx.toFloat() val totalPx = h * (1 + (effectiveWeeks - 1) * (1f - collapseProgress)) @@ -188,7 +199,7 @@ private fun WeekRow( !hasAnchor -> weekIndex * h - collapseProgress * weeksSize * h isAnchor -> anchorIndex * h * (1f - phase1) isAbove -> weekIndex * h - phase1 * anchorIndex * h - isBelow -> weekIndex * h - phase1 * anchorIndex * h + isBelow -> weekIndex * h - phase1 * anchorIndex * h - phase2 * belowRowsHeight else -> weekIndex * h } } else 0f @@ -201,9 +212,17 @@ private fun WeekRow( else -> 1f } - if (isAnchor || isBelow) { - Log.d(TAG_CMP, "WeekRow[$weekIndex]: isAnchor=$isAnchor isAbove=$isAbove isBelow=$isBelow phase1=$phase1 phase2=$phase2 yOffsetPx=$yOffsetPx rowAlpha=$rowAlpha collapseProgress=$collapseProgress") - } + val frameTimeNs = System.nanoTime() + Log.d( + TAG_CMP, + "WeekRow[$weekIndex]: " + + "isAnchor=$isAnchor isAbove=$isAbove isBelow=$isBelow " + + "phase1=$phase1 phase2=$phase2 phase1End=$phase1End " + + "belowRowsHeight=$belowRowsHeight rowHeightPx=$rowHeightPx " + + "yOffsetPx=$yOffsetPx rowAlpha=$rowAlpha " + + "collapseProgress=$collapseProgress " + + "frameNs=$frameTimeNs" + ) if (rowAlpha > 0.01f) { Row( diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt index f22b734..c68210a 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -48,6 +48,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.SideEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf @@ -69,7 +70,6 @@ import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.datetime.DatePeriod import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone import kotlinx.datetime.number @@ -82,6 +82,7 @@ import plus.rua.project.composeTraceEndSection import kotlin.math.abs import kotlin.time.Clock import androidx.lifecycle.viewmodel.compose.viewModel +import android.util.Log /** * 日历主界面,包含月/周视图切换、折叠动画和年视图共享元素转场。 @@ -118,6 +119,9 @@ fun CalendarMonthView( animationSpec = spring(stiffness = Spring.StiffnessMedium), label = "collapseProgress" ) + SideEffect { + Log.d("CalendarExpandAnim", "View: target=$collapseProgress animated=$animatedCollapseProgress isCollapsed=$isCollapsed") + } val density = LocalDensity.current val coroutineScope = rememberCoroutineScope() @@ -238,7 +242,6 @@ fun CalendarMonthView( CalendarPagerArea( selectedDate = selectedDate, today = today, - isCollapsed = isCollapsed, collapseProgress = animatedCollapseProgress, showLegalHoliday = showLegalHoliday, rowHeightPx = rowHeightPx, @@ -463,7 +466,6 @@ private fun MenuIcon(color: Color, modifier: Modifier = Modifier) { private fun CalendarPagerArea( selectedDate: LocalDate, today: LocalDate, - isCollapsed: Boolean, collapseProgress: Float, showLegalHoliday: Boolean, rowHeightPx: Int, @@ -520,66 +522,20 @@ private fun CalendarPagerArea( modifier } - // 延迟切换:等折叠 spring 动画完全稳定后再切到 WeekPager,避免视觉跳跃 - var showWeekPager by remember { mutableStateOf(false) } - - LaunchedEffect(isCollapsed, collapseProgress) { - if (isCollapsed && collapseProgress >= 0.999f) { - delay(50) - showWeekPager = true - } else if (!isCollapsed) { - showWeekPager = false - } - } - - AnimatedContent( - targetState = showWeekPager, - transitionSpec = { fadeIn(tween(80)) togetherWith fadeOut(tween(80)) }, - label = "pager_switch", + CalendarPager( + selectedDate = selectedDate, + today = today, + onDateClick = onDateClick, + onMonthChanged = onMonthChanged, + collapseProgress = collapseProgress, + rowHeightPx = rowHeightPx, + effectiveWeeks = effectiveWeeks, + shiftKindAt = shiftKindAt, + showLegalHoliday = showLegalHoliday, + onRowHeightMeasured = onRowHeightMeasured, + pagerState = pagerState, modifier = pagerModifier - ) { useWeekPager -> - if (useWeekPager) { - WeekPager( - selectedDate = selectedDate, - today = today, - onDateClick = onDateClick, - onWeekChanged = { weekMonday -> - val weekSunday = weekMonday.plus(DatePeriod(days = 6)) - val date = when { - today in weekMonday..weekSunday -> today - weekMonday.month != weekSunday.month -> { - if (weekMonday < selectedDate) { - @Suppress("DEPRECATION") - LocalDate(weekSunday.year, weekSunday.month.number, 1) - } else { - weekMonday - } - } - else -> weekMonday - } - onDateClick(date) - }, - shiftKindAt = shiftKindAt, - showLegalHoliday = showLegalHoliday, - modifier = Modifier - ) - } else { - CalendarPager( - selectedDate = selectedDate, - today = today, - onDateClick = onDateClick, - onMonthChanged = onMonthChanged, - collapseProgress = collapseProgress, - rowHeightPx = rowHeightPx, - effectiveWeeks = effectiveWeeks, - shiftKindAt = shiftKindAt, - showLegalHoliday = showLegalHoliday, - onRowHeightMeasured = onRowHeightMeasured, - pagerState = pagerState, - modifier = Modifier - ) - } - } + ) } @Composable