From 216ebbf990555f8282371199b8d1cc4bb86d9b2e Mon Sep 17 00:00:00 2001 From: meyou <2636699780@qq.com> Date: Sat, 16 May 2026 16:59:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A6=96=E6=AC=A1=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=88=87=E6=8D=A2=E5=B9=B4=E8=A7=86=E5=9B=BE=E6=97=A0?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 始终组合年视图 HorizontalPager 层(通过 graphicsLayer.alpha=0 隐藏), 避免首次进入时 Pager 组合延迟导致动画首帧丢失。 --- .../plus/rua/project/ui/CalendarMonthView.kt | 76 +++++++++---------- 1 file changed, 37 insertions(+), 39 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 b2bf002..b92a46f 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -270,47 +270,45 @@ fun CalendarMonthView( } } - // 年视图层:HorizontalPager 支持左右滑动切年 - if (viewModel.isYearView || yearProgress > 0.01f) { - HorizontalPager( - state = yearPagerState, - beyondViewportPageCount = 1, - flingBehavior = PagerDefaults.flingBehavior(state = yearPagerState), - modifier = Modifier - .fillMaxSize() - .graphicsLayer { - scaleX = yearScale - scaleY = yearScale - alpha = yearAlpha - transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY) + // 年视图层:始终组合以避免首次进入时的组合延迟导致动画丢失 + HorizontalPager( + state = yearPagerState, + beyondViewportPageCount = 1, + flingBehavior = PagerDefaults.flingBehavior(state = yearPagerState), + modifier = Modifier + .fillMaxSize() + .graphicsLayer { + scaleX = yearScale + scaleY = yearScale + alpha = yearAlpha + transformOrigin = TransformOrigin(anchorPivotX, anchorPivotY) + } + .padding(horizontal = HORIZONTAL_PADDING_DP.dp) + ) { page -> + val pageYear = viewModel.selectedDate.year + (page - START_PAGE) + YearGridView( + year = pageYear, + selectedMonth = if (pageYear == currentYear) currentMonth else 0, + today = today, + onMonthClick = { month -> + viewModel.selectMonthFromYearView(month) + @Suppress("DEPRECATION") // monthNumber 无替代 API + val targetPage = yearMonthToPage( + viewModel.yearViewYear, month, + today.year, today.month.number + ) + if (targetPage != pagerState.currentPage) { + coroutineScope.launch { pagerState.scrollToPage(targetPage) } } - .padding(horizontal = HORIZONTAL_PADDING_DP.dp) - ) { page -> - val pageYear = viewModel.selectedDate.year + (page - START_PAGE) - YearGridView( - year = pageYear, - selectedMonth = if (pageYear == currentYear) currentMonth else 0, - today = today, - onMonthClick = { month -> - viewModel.selectMonthFromYearView(month) - @Suppress("DEPRECATION") // monthNumber 无替代 API - val targetPage = yearMonthToPage( - viewModel.yearViewYear, month, - today.year, today.month.number - ) - if (targetPage != pagerState.currentPage) { - coroutineScope.launch { pagerState.scrollToPage(targetPage) } - } - }, - onYearChange = { newYear -> - val offset = newYear - pageYear - val targetPage = yearPagerState.currentPage + offset - if (targetPage != yearPagerState.currentPage) { - coroutineScope.launch { yearPagerState.animateScrollToPage(targetPage) } - } + }, + onYearChange = { newYear -> + val offset = newYear - pageYear + val targetPage = yearPagerState.currentPage + offset + if (targetPage != yearPagerState.currentPage) { + coroutineScope.launch { yearPagerState.animateScrollToPage(targetPage) } } - ) - } + } + ) } // BottomCard:年视图时隐藏