修复月→年视图切换卡顿:Pager 缓存降为 0 + 移除延迟预组合
Perfetto trace 分析发现严重卡顿根因:
- MonthView→YearView 切换耗时 2435ms
- Choreographer#doFrame 单帧超时 4288ms
- compose📟cache_window:keepAroundItems 阻塞 554ms×2
- Compose:onForgotten 组件销毁 600ms
修复:
1. CalendarPager/WeekPager/年视图 Pager 的 beyondViewportPageCount 从 1→0
月视图缓存页从 3 页(126 DayCell)降至 1 页(42 DayCell)
2. 移除 yearPagerBeyondViewport 延迟预组合机制(不再需要)
This commit is contained in:
parent
a478ecb1bd
commit
9fd877485f
@ -51,7 +51,6 @@ import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.datetime.DatePeriod
|
||||
import kotlinx.datetime.LocalDate
|
||||
@ -93,24 +92,11 @@ fun CalendarMonthView(
|
||||
var screenHeightPx by remember { mutableIntStateOf(0) }
|
||||
var calendarContentHeightPx by remember { mutableIntStateOf(0) }
|
||||
var isMenuExpanded by remember { mutableStateOf(false) }
|
||||
var yearPagerBeyondViewport by remember { mutableStateOf(0) }
|
||||
|
||||
// 视图切换时自动关闭菜单
|
||||
LaunchedEffect(viewModel.isYearView) {
|
||||
isMenuExpanded = false
|
||||
}
|
||||
|
||||
// 年视图动画完成后再恢复预组合,避免动画期间触发邻页组合阻塞帧
|
||||
LaunchedEffect(viewModel.isYearView) {
|
||||
if (viewModel.isYearView) {
|
||||
snapshotFlow { viewModel.yearViewProgress }
|
||||
.first { it >= 1f }
|
||||
yearPagerBeyondViewport = 1
|
||||
} else {
|
||||
yearPagerBeyondViewport = 0
|
||||
}
|
||||
}
|
||||
|
||||
val pagerState = rememberPagerState(initialPage = START_PAGE, pageCount = { Int.MAX_VALUE })
|
||||
|
||||
// 年视图分页器
|
||||
@ -364,7 +350,7 @@ fun CalendarMonthView(
|
||||
)
|
||||
HorizontalPager(
|
||||
state = yearPagerState,
|
||||
beyondViewportPageCount = yearPagerBeyondViewport,
|
||||
beyondViewportPageCount = 0,
|
||||
flingBehavior = PagerDefaults.flingBehavior(state = yearPagerState),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
||||
@ -67,7 +67,7 @@ fun CalendarPager(
|
||||
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1,
|
||||
beyondViewportPageCount = 0,
|
||||
flingBehavior = PagerDefaults.flingBehavior(state = pagerState),
|
||||
modifier = modifier
|
||||
) { page ->
|
||||
|
||||
@ -66,7 +66,7 @@ fun WeekPager(
|
||||
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1,
|
||||
beyondViewportPageCount = 0,
|
||||
flingBehavior = PagerDefaults.flingBehavior(state = pagerState),
|
||||
modifier = modifier
|
||||
) { page ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user