revert: 回退 graphicsLayer 优化,实机 GPU 合成开销过大
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) <noreply@anthropic.com>
This commit is contained in:
parent
73b176a95e
commit
bb0a72006d
@ -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 ->
|
||||
|
||||
@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user