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 ce3c726..5e66966 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf @@ -61,6 +62,19 @@ fun CalendarMonthView( val pagerState = rememberPagerState(initialPage = START_PAGE, pageCount = { Int.MAX_VALUE }) + // 折叠态 WeekPager 切月时,持续同步 CalendarPager 的 pagerState, + // 避免展开时 CalendarPager 首帧显示旧月份导致闪白 + LaunchedEffect(viewModel.selectedDate) { + @Suppress("DEPRECATION") // monthNumber 无替代 API + val targetPage = yearMonthToPage( + viewModel.selectedDate.year, viewModel.selectedDate.month.number, + today.year, today.month.number + ) + if (targetPage != pagerState.currentPage) { + pagerState.scrollToPage(targetPage) + } + } + val collapseProgress = viewModel.collapseProgress val headerHeightPx = monthHeaderHeightPx + weekdayHeaderHeightPx val rowPaddingPx = with(density) { ROW_PADDING_DP.dp.toPx() }.toInt() 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 6d96511..1d29e21 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt @@ -52,17 +52,6 @@ fun CalendarPager( val initialMonth = remember { today.month.number } val coroutineScope = rememberCoroutineScope() - // 展开后同步页面到 selectedDate 所在月份(修复折叠态切月后展开闪跳) - LaunchedEffect(Unit) { - @Suppress("DEPRECATION") // monthNumber 无替代 API - val targetPage = yearMonthToPage( - selectedDate.year, selectedDate.month.number, initialYear, initialMonth - ) - if (targetPage != pagerState.currentPage) { - pagerState.scrollToPage(targetPage) - } - } - // 跳过初始发射,保留首次渲染时的"今天"选中状态 LaunchedEffect(pagerState) { snapshotFlow { pagerState.settledPage }.drop(1).collect { page ->