From bb0a72006d7e085c11102e404a5747cf59fe014d Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 25 May 2026 17:25:22 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E5=9B=9E=E9=80=80=20graphicsLayer=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E5=AE=9E=E6=9C=BA=20GPU=20=E5=90=88?= =?UTF-8?q?=E6=88=90=E5=BC=80=E9=94=80=E8=BF=87=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit graphicsLayer 创建的离屏 layer 在实体机上导致 slow draw commands 激增, 整体体验比重组更卡。回退以下改动: - WeekRow: graphicsLayer → offset + alpha - CalendarPager: graphicsLayer → alpha - WeekPager: graphicsLayer → alpha - YearGridView: graphicsLayer → alpha - BottomCard: graphicsLayer → offset + alpha - layoutReady: graphicsLayer → alpha 保留的优化: - DayCell produceState 上移(42 协程 → 1 协程) - remember 稳定化 lambda 和计算 Co-Authored-By: Claude Opus 4.7 (1M context) --- .../kotlin/plus/rua/project/ui/CalendarMonthPage.kt | 9 ++++----- .../kotlin/plus/rua/project/ui/CalendarMonthView.kt | 13 +++++-------- .../kotlin/plus/rua/project/ui/CalendarPager.kt | 4 ++-- .../main/kotlin/plus/rua/project/ui/WeekPager.kt | 4 ++-- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt index 73aca94..2834a90 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt @@ -15,7 +15,8 @@ import androidx.compose.runtime.produceState import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clipToBounds -import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.draw.alpha +import androidx.compose.foundation.layout.offset import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp @@ -210,10 +211,8 @@ private fun WeekRow( if (isAnchor && phase1 >= 1f) Modifier.background(MaterialTheme.colorScheme.surface) else Modifier ) - .graphicsLayer { - translationY = yOffsetPx - this.alpha = rowAlpha - } + .offset(y = with(density) { yOffsetPx.toDp() }) + .alpha(rowAlpha) .then( if (weekIndex == 0 && rowHeightPx == 0) { Modifier.onSizeChanged { size -> diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt index 3a9fc32..b259462 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -29,6 +29,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize 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.foundation.layout.size import androidx.compose.foundation.layout.statusBarsPadding @@ -193,7 +194,7 @@ fun CalendarMonthView( modifier = Modifier .fillMaxSize() .background(MaterialTheme.colorScheme.background) - .graphicsLayer { alpha = if (layoutReady) 1f else 0f } + .alpha(if (layoutReady) 1f else 0f) ) { Column( modifier = Modifier @@ -323,7 +324,7 @@ fun CalendarMonthView( }, sharedTransitionScope = sharedScope, animatedVisibilityScope = this@AnimatedContent, - modifier = Modifier.graphicsLayer { this.alpha = crossFadeAlpha } + modifier = Modifier.alpha(crossFadeAlpha) ) } } @@ -584,8 +585,6 @@ private fun BottomCardArea( animationSpec = tween(350, delayMillis = 100, easing = FastOutSlowInEasing), label = "bottomCardSlide" ) - val slideOffsetY = with(density) { (slideProgress * 200).dp.toPx() } - // 延迟一帧显示 BottomCard,避免 AnimatedGif 和 lunar 计算阻塞首帧 var hasLoaded by remember { mutableStateOf(false) } LaunchedEffect(Unit) { @@ -609,10 +608,8 @@ private fun BottomCardArea( onExpandDragEnd = { viewModel.onExpandDragEnd() }, dragRangePx = dragRangePx, modifier = modifier - .graphicsLayer { - translationY = slideOffsetY - this.alpha = 1f - slideProgress - } + .offset(y = with(density) { (slideProgress * 200).dp }) + .alpha(1f - slideProgress) ) } } diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarPager.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarPager.kt index 6388821..73b8a1b 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarPager.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarPager.kt @@ -11,7 +11,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.draw.alpha import kotlinx.coroutines.flow.drop import kotlinx.coroutines.launch import kotlinx.datetime.LocalDate @@ -117,7 +117,7 @@ fun CalendarPager( shiftKindAt = shiftKindAt, showLegalHoliday = showLegalHoliday, onRowHeightMeasured = onRowHeightMeasured, - modifier = Modifier.graphicsLayer { this.alpha = alpha } + modifier = Modifier.alpha(alpha) ) } } \ No newline at end of file diff --git a/core/src/main/kotlin/plus/rua/project/ui/WeekPager.kt b/core/src/main/kotlin/plus/rua/project/ui/WeekPager.kt index 42d4652..602e402 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/WeekPager.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/WeekPager.kt @@ -13,7 +13,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.draw.alpha import androidx.compose.ui.unit.dp import kotlinx.coroutines.flow.drop import kotlinx.datetime.DatePeriod @@ -87,7 +87,7 @@ fun WeekPager( val weekMonday = pageToWeekMonday(page, initialWeekMonday) Row( modifier = Modifier - .graphicsLayer { this.alpha = alpha } + .alpha(alpha) .fillMaxWidth() .padding(vertical = ROW_PADDING_DP.dp) ) {