修复年视图缩放动画丢失:progress 提前到重组阶段读取

graphicsLayer { } lambda 在 draw 阶段执行,内部直接读取 viewModel.yearViewProgress
不会被 Compose 标记为可观察状态,导致 Animatable 每帧 value 变化不触发重绘,
动画只在 isYearView 翻转时重组一次然后卡到动画完成。

修复:在 if (isYearView) / if (!isYearView) 块内先读取 progress 为局部变量,
graphicsLayer lambda 通过捕获使用,让 Animatable 变化能驱动重组进而触发重绘。
This commit is contained in:
xfy 2026-05-18 17:37:40 +08:00
parent a4bd56a8a9
commit 3a3e6014d8

View File

@ -233,14 +233,15 @@ fun CalendarMonthView(
dragRangeMinPx
}
val monthProgress = 1f - viewModel.yearViewProgress
Box(
modifier = Modifier
.fillMaxSize()
.graphicsLayer {
val progress = if (viewModel.isYearView) viewModel.yearViewProgress else 1f - viewModel.yearViewProgress
scaleX = lerp(0.3f, 1f, progress)
scaleY = lerp(0.3f, 1f, progress)
alpha = progress.coerceIn(0f, 1f)
val scale = lerp(0.3f, 1f, monthProgress)
scaleX = scale
scaleY = scale
alpha = monthProgress.coerceIn(0f, 1f)
transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY)
}
) {
@ -335,16 +336,16 @@ fun CalendarMonthView(
// 年视图层标题固定HorizontalPager 只包裹网格。
if (viewModel.isYearView) {
val yearProgress = viewModel.yearViewProgress
composeTraceBeginSection("YearView:Compose")
Column(
modifier = Modifier
.fillMaxSize()
.graphicsLayer {
val progress = if (viewModel.isYearView) viewModel.yearViewProgress else 1f - viewModel.yearViewProgress
val scale = lerp(3.3f, 1f, progress)
val scale = lerp(3.3f, 1f, yearProgress)
scaleX = scale
scaleY = scale
alpha = progress.coerceIn(0f, 1f)
alpha = yearProgress.coerceIn(0f, 1f)
transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY)
}
.padding(horizontal = HORIZONTAL_PADDING_DP.dp)