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..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 }) // 年视图分页器 @@ -233,6 +219,9 @@ fun CalendarMonthView( } val monthProgress = 1f - viewModel.yearViewProgress + // 组合阶段计算:lambda 捕获快照值,避免 draw 阶段读到已更新的 rowHeightPx + // 但 layout 仍用旧值导致行堆叠 + val layoutReady = rowHeightPx > 0 Box( modifier = Modifier .fillMaxSize() @@ -240,7 +229,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) } ) { @@ -361,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 -> 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)