From 5d6b2071e2c9879be49d2c925e150de970506e8a Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 18 May 2026 14:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=8C=E5=81=8F=E7=A7=BB=E4=BB=8E=20offset(D?= =?UTF-8?q?p)=20=E6=94=B9=E4=B8=BA=20graphicsLayer(translationY)=20?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=AF=8F=E5=B8=A7=20layout=20pass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit offset 触发 layout-phase 重测量,trace 中 measure 最高 1266ms。 graphicsLayer 只触发 draw-phase redraw,跳过 layout。 Co-Authored-By: Claude Opus 4.7 --- .../plus/rua/project/ui/CalendarMonthPage.kt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt index a8c64c4..c3ff135 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable @@ -103,16 +102,15 @@ fun CalendarMonthPage( val isAbove = hasAnchor && weekIndex < anchorIndex val isBelow = hasAnchor && weekIndex > anchorIndex - val yOffsetDp = if (rowHeightPx > 0) { - val yPx = when { + val yOffsetPx = if (rowHeightPx > 0) { + when { !hasAnchor -> weekIndex * h - collapseProgress * weeks.size * h isAnchor -> anchorIndex * h * (1f - phase1) isAbove -> weekIndex * h - phase1 * anchorIndex * h isBelow -> weekIndex * h - phase1 * anchorIndex * h - phase2 * belowRowsHeight else -> weekIndex * h } - with(density) { yPx.toDp() } - } else 0.dp + } else 0f val rowAlpha = when { !hasAnchor -> (1f - collapseProgress).coerceIn(0f, 1f) @@ -135,7 +133,10 @@ fun CalendarMonthPage( if (isAnchor && phase1 >= 1f) Modifier.background(MaterialTheme.colorScheme.surface) else Modifier ) - .offset(y = yOffsetDp) + .graphicsLayer { + translationY = yOffsetPx + alpha = rowAlpha + } .then( if (weekIndex == 0 && rowHeightPx == 0) { Modifier.onSizeChanged { size -> @@ -146,10 +147,6 @@ fun CalendarMonthPage( } else Modifier ) .padding(vertical = ROW_PADDING_DP.dp) - .then( - if (rowAlpha < 1f) Modifier.graphicsLayer { alpha = rowAlpha } - else Modifier - ) ) { week.forEach { dayData -> DayCell(