perf: 优化年月切换卡顿
Perfetto trace 分析: - YearGridView 首帧 168ms: 12 个 MiniMonth 各创建 sharedElement 节点,但仅 1 个 key 匹配 CalendarPager - compose:lazy:prefetch 最长 703ms: CalendarPager 预加载相邻页 修复: - YearGridView: 仅选中的月份使用 sharedElement(11→1 个), 减少首次组合的 modifier 节点创建开销 - CalendarPager: beyondViewportPageCount 1→0,消除预加载卡顿
This commit is contained in:
parent
80ab328906
commit
5158b99800
@ -77,7 +77,7 @@ fun CalendarPager(
|
||||
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1,
|
||||
beyondViewportPageCount = 0,
|
||||
flingBehavior = PagerDefaults.flingBehavior(state = pagerState),
|
||||
modifier = modifier
|
||||
) { page ->
|
||||
|
||||
@ -167,12 +167,12 @@ fun YearGridView(
|
||||
) {
|
||||
(0 until 3).forEach { col ->
|
||||
val month = row * 3 + col + 1
|
||||
val sharedKey = "month_grid_${year}_$month"
|
||||
val isSelectedMonth = month == selectedMonth
|
||||
with(sharedTransitionScope) {
|
||||
MiniMonth(
|
||||
year = year,
|
||||
month = month,
|
||||
isSelected = month == selectedMonth,
|
||||
isSelected = isSelectedMonth,
|
||||
today = today,
|
||||
days = monthDays[month - 1],
|
||||
colors = colors,
|
||||
@ -182,13 +182,19 @@ fun YearGridView(
|
||||
onClick = { onMonthClick(month) },
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.sharedElement(
|
||||
sharedContentState = rememberSharedContentState(
|
||||
key = sharedKey
|
||||
),
|
||||
animatedVisibilityScope = animatedVisibilityScope,
|
||||
boundsTransform = { _, _ ->
|
||||
tween(400, easing = FastOutSlowInEasing)
|
||||
.then(
|
||||
if (isSelectedMonth) {
|
||||
Modifier.sharedElement(
|
||||
sharedContentState = rememberSharedContentState(
|
||||
key = "month_grid_${year}_$month"
|
||||
),
|
||||
animatedVisibilityScope = animatedVisibilityScope,
|
||||
boundsTransform = { _, _ ->
|
||||
tween(400, easing = FastOutSlowInEasing)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user