From d5b7d2cd8a979b4e6fce9d3720684ec1203d4bdd Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 18 May 2026 15:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=AE=A1=E7=AE=97=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?=20dp=E2=86=92px=20=E8=BD=AC=E6=8D=A2=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E6=AF=8F=E5=B8=A7=E9=87=8D=E5=A4=8D=20density=20?= =?UTF-8?q?=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cardGapExpandedPx/cardGapCollapsedPx/rowPaddingPx/horizontalPaddingPx 移入 remember,每帧只做一次浮点插值而非完整 density 转换。 Co-Authored-By: Claude Opus 4.7 --- .../plus/rua/project/ui/CalendarMonthView.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 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 f0ebbe3..9ab2b6b 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -138,14 +138,12 @@ fun CalendarMonthView( val collapseProgress = viewModel.collapseProgress val headerHeightPx = monthHeaderHeightPx + weekdayHeaderHeightPx - val rowPaddingPx = with(density) { ROW_PADDING_DP.dp.toPx() }.toInt() - val cardGapPx = with(density) { - lerp( - CARD_GAP_EXPANDED_DP.toFloat(), - CARD_GAP_COLLAPSED_DP.toFloat(), - collapseProgress - ).dp.toPx() - }.toInt() + + // 预计算固定 dp→px,避免每帧重复 density 转换 + val cardGapExpandedPx = remember { with(density) { CARD_GAP_EXPANDED_DP.dp.toPx() } } + val cardGapCollapsedPx = remember { with(density) { CARD_GAP_COLLAPSED_DP.dp.toPx() } } + val rowPaddingPx = remember { with(density) { ROW_PADDING_DP.dp.toPx() } }.toInt() + val cardGapPx = lerp(cardGapExpandedPx, cardGapCollapsedPx, collapseProgress).toInt() val interpolatedWeeks by remember { derivedStateOf { @@ -162,11 +160,13 @@ fun CalendarMonthView( } } + // 预计算固定 dp→px,避免每帧重复 density 转换 + val horizontalPaddingPx = remember { with(density) { (HORIZONTAL_PADDING_DP * 2).dp.toPx() } } + val rowPadding2Px = remember { with(density) { (ROW_PADDING_DP * 2).dp.toPx() } } + val estimatedRowHeightPx = if (screenWidthPx > 0) { - val cellWidth = - (screenWidthPx - with(density) { (HORIZONTAL_PADDING_DP * 2).dp.toPx() }) / 7 - val rowPadding = with(density) { (ROW_PADDING_DP * 2).dp.toPx() } - (cellWidth + rowPadding).toInt() + val cellWidth = (screenWidthPx - horizontalPaddingPx) / 7 + (cellWidth + rowPadding2Px).toInt() } else 0 val effectiveRowHeightPx = if (rowHeightPx > 0) rowHeightPx else estimatedRowHeightPx