From 0962d1321686d40d10de4b328a3ca9c29234fdba Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 18 May 2026 15:06:04 +0800 Subject: [PATCH] =?UTF-8?q?gridHeightPx/calendarAreaHeightPx/cardHeightPx?= =?UTF-8?q?=20=E5=8C=85=E8=A3=B9=20derivedStateOf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将依赖 collapseProgress 的中间计算移入 derivedStateOf, 确保只在被读取时才计算,避免不必要的中间对象创建。 Co-Authored-By: Claude Opus 4.7 --- .../plus/rua/project/ui/CalendarMonthView.kt | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) 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 9ab2b6b..1aa4421 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -172,18 +172,28 @@ fun CalendarMonthView( val effectiveRowHeightPx = if (rowHeightPx > 0) rowHeightPx else estimatedRowHeightPx val effectiveWeeks = interpolatedWeeks - val gridHeightPx = if (effectiveRowHeightPx > 0) { - val rowH = effectiveRowHeightPx.toFloat() - if (collapseProgress > OFFSET_FRACTION_THRESHOLD) { - (rowH * (1 + (effectiveWeeks - 1) * (1f - collapseProgress))).toInt() - } else { - (rowH * effectiveWeeks).toInt() + val gridHeightPx by remember { + derivedStateOf { + if (effectiveRowHeightPx > 0) { + val rowH = effectiveRowHeightPx.toFloat() + if (collapseProgress > OFFSET_FRACTION_THRESHOLD) { + (rowH * (1 + (effectiveWeeks - 1) * (1f - collapseProgress))).toInt() + } else { + (rowH * effectiveWeeks).toInt() + } + } else 0 } - } else 0 + } - val calendarAreaHeightPx = headerHeightPx + gridHeightPx + rowPaddingPx + cardGapPx - val cardHeightPx = - if (screenHeightPx > 0 && calendarAreaHeightPx > 0) screenHeightPx - calendarAreaHeightPx else 0 + val calendarAreaHeightPx by remember { + derivedStateOf { headerHeightPx + gridHeightPx + rowPaddingPx + cardGapPx } + } + + val cardHeightPx by remember { + derivedStateOf { + if (screenHeightPx > 0 && calendarAreaHeightPx > 0) screenHeightPx - calendarAreaHeightPx else 0 + } + } val pagerModifier = if (rowHeightPx > 0 && gridHeightPx > 0) { Modifier