gridHeightPx/calendarAreaHeightPx/cardHeightPx 包裹 derivedStateOf

将依赖 collapseProgress 的中间计算移入 derivedStateOf,
确保只在被读取时才计算,避免不必要的中间对象创建。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-05-18 15:06:04 +08:00
parent d5b7d2cd8a
commit 0962d13216

View File

@ -172,18 +172,28 @@ fun CalendarMonthView(
val effectiveRowHeightPx = if (rowHeightPx > 0) rowHeightPx else estimatedRowHeightPx val effectiveRowHeightPx = if (rowHeightPx > 0) rowHeightPx else estimatedRowHeightPx
val effectiveWeeks = interpolatedWeeks val effectiveWeeks = interpolatedWeeks
val gridHeightPx = if (effectiveRowHeightPx > 0) { val gridHeightPx by remember {
val rowH = effectiveRowHeightPx.toFloat() derivedStateOf {
if (collapseProgress > OFFSET_FRACTION_THRESHOLD) { if (effectiveRowHeightPx > 0) {
(rowH * (1 + (effectiveWeeks - 1) * (1f - collapseProgress))).toInt() val rowH = effectiveRowHeightPx.toFloat()
} else { if (collapseProgress > OFFSET_FRACTION_THRESHOLD) {
(rowH * effectiveWeeks).toInt() (rowH * (1 + (effectiveWeeks - 1) * (1f - collapseProgress))).toInt()
} else {
(rowH * effectiveWeeks).toInt()
}
} else 0
} }
} else 0 }
val calendarAreaHeightPx = headerHeightPx + gridHeightPx + rowPaddingPx + cardGapPx val calendarAreaHeightPx by remember {
val cardHeightPx = derivedStateOf { headerHeightPx + gridHeightPx + rowPaddingPx + cardGapPx }
if (screenHeightPx > 0 && calendarAreaHeightPx > 0) screenHeightPx - calendarAreaHeightPx else 0 }
val cardHeightPx by remember {
derivedStateOf {
if (screenHeightPx > 0 && calendarAreaHeightPx > 0) screenHeightPx - calendarAreaHeightPx else 0
}
}
val pagerModifier = if (rowHeightPx > 0 && gridHeightPx > 0) { val pagerModifier = if (rowHeightPx > 0 && gridHeightPx > 0) {
Modifier Modifier