From a478ecb1bd819291b8be1f1cf8db2fbbbdd6c394 Mon Sep 17 00:00:00 2001 From: meyou <2636699780@qq.com> Date: Mon, 18 May 2026 22:06:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=88=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E9=A6=96=E5=B8=A7=E8=A1=8C=E5=A0=86=E5=8F=A0=EF=BC=9A?= =?UTF-8?q?rowHeightPx=20=E6=9C=AA=E5=B0=B1=E7=BB=AA=E6=97=B6=20alpha=3D0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit draw 阶段已读到更新后的 rowHeightPx,但 layout 仍用旧值时会出现行堆叠。 增加 layoutReady 守卫,首帧 rowHeightPx==0 时直接隐藏月视图。 --- .../kotlin/plus/rua/project/ui/CalendarMonthView.kt | 5 ++++- .../kotlin/plus/rua/project/CalendarViewModelTest.kt | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt index 324015d..1e1ba24 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -233,6 +233,9 @@ fun CalendarMonthView( } val monthProgress = 1f - viewModel.yearViewProgress + // 组合阶段计算:lambda 捕获快照值,避免 draw 阶段读到已更新的 rowHeightPx + // 但 layout 仍用旧值导致行堆叠 + val layoutReady = rowHeightPx > 0 Box( modifier = Modifier .fillMaxSize() @@ -240,7 +243,7 @@ fun CalendarMonthView( val scale = lerp(0.3f, 1f, monthProgress) scaleX = scale scaleY = scale - alpha = monthProgress.coerceIn(0f, 1f) + alpha = if (layoutReady) monthProgress.coerceIn(0f, 1f) else 0f transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY) } ) { diff --git a/shared/src/commonTest/kotlin/plus/rua/project/CalendarViewModelTest.kt b/shared/src/commonTest/kotlin/plus/rua/project/CalendarViewModelTest.kt index 0361dec..81c6947 100644 --- a/shared/src/commonTest/kotlin/plus/rua/project/CalendarViewModelTest.kt +++ b/shared/src/commonTest/kotlin/plus/rua/project/CalendarViewModelTest.kt @@ -18,7 +18,6 @@ class CalendarViewModelTest { private val fixedInstant = Instant.parse("2026-05-15T00:00:00Z") private val testClock = FixedClock(fixedInstant) - private fun createViewModel(): CalendarViewModel { val scope = CoroutineScope(Dispatchers.Unconfined) return CalendarViewModel(coroutineScope = scope, clock = testClock) From 9fd877485f603149f3cce21ce2a3f05f9826bb11 Mon Sep 17 00:00:00 2001 From: meyou <2636699780@qq.com> Date: Mon, 18 May 2026 22:49:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=88=E2=86=92?= =?UTF-8?q?=E5=B9=B4=E8=A7=86=E5=9B=BE=E5=88=87=E6=8D=A2=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=EF=BC=9APager=20=E7=BC=93=E5=AD=98=E9=99=8D=E4=B8=BA=200=20+?= =?UTF-8?q?=20=E7=A7=BB=E9=99=A4=E5=BB=B6=E8=BF=9F=E9=A2=84=E7=BB=84?= =?UTF-8?q?=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Perfetto trace 分析发现严重卡顿根因: - MonthView→YearView 切换耗时 2435ms - Choreographer#doFrame 单帧超时 4288ms - compose:pager:cache_window:keepAroundItems 阻塞 554ms×2 - Compose:onForgotten 组件销毁 600ms 修复: 1. CalendarPager/WeekPager/年视图 Pager 的 beyondViewportPageCount 从 1→0 月视图缓存页从 3 页(126 DayCell)降至 1 页(42 DayCell) 2. 移除 yearPagerBeyondViewport 延迟预组合机制(不再需要) --- .../plus/rua/project/ui/CalendarMonthView.kt | 16 +--------------- .../kotlin/plus/rua/project/ui/CalendarPager.kt | 2 +- .../kotlin/plus/rua/project/ui/WeekPager.kt | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt index 1e1ba24..11d6366 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -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() diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt index 711a6b7..ee9ef5a 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt @@ -67,7 +67,7 @@ fun CalendarPager( HorizontalPager( state = pagerState, - beyondViewportPageCount = 1, + beyondViewportPageCount = 0, flingBehavior = PagerDefaults.flingBehavior(state = pagerState), modifier = modifier ) { page -> diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt index 6ba5664..d351cea 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt @@ -66,7 +66,7 @@ fun WeekPager( HorizontalPager( state = pagerState, - beyondViewportPageCount = 1, + beyondViewportPageCount = 0, flingBehavior = PagerDefaults.flingBehavior(state = pagerState), modifier = modifier ) { page ->