修复年视图缩放动画丢失: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 dragRangeMinPx
} }
val monthProgress = 1f - viewModel.yearViewProgress
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.graphicsLayer { .graphicsLayer {
val progress = if (viewModel.isYearView) viewModel.yearViewProgress else 1f - viewModel.yearViewProgress val scale = lerp(0.3f, 1f, monthProgress)
scaleX = lerp(0.3f, 1f, progress) scaleX = scale
scaleY = lerp(0.3f, 1f, progress) scaleY = scale
alpha = progress.coerceIn(0f, 1f) alpha = monthProgress.coerceIn(0f, 1f)
transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY) transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY)
} }
) { ) {
@ -335,16 +336,16 @@ fun CalendarMonthView(
// 年视图层标题固定HorizontalPager 只包裹网格。 // 年视图层标题固定HorizontalPager 只包裹网格。
if (viewModel.isYearView) { if (viewModel.isYearView) {
val yearProgress = viewModel.yearViewProgress
composeTraceBeginSection("YearView:Compose") composeTraceBeginSection("YearView:Compose")
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.graphicsLayer { .graphicsLayer {
val progress = if (viewModel.isYearView) viewModel.yearViewProgress else 1f - viewModel.yearViewProgress val scale = lerp(3.3f, 1f, yearProgress)
val scale = lerp(3.3f, 1f, progress)
scaleX = scale scaleX = scale
scaleY = scale scaleY = scale
alpha = progress.coerceIn(0f, 1f) alpha = yearProgress.coerceIn(0f, 1f)
transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY) transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY)
} }
.padding(horizontal = HORIZONTAL_PADDING_DP.dp) .padding(horizontal = HORIZONTAL_PADDING_DP.dp)