From e663ed5c8eeae16ee78a22b544e53aed7b29f132 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 23 Jul 2026 15:16:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=B9=B4=E6=9C=88=E8=A7=86=E5=9B=BE=E5=8A=A8=E7=94=BB=E6=9C=9F?= =?UTF-8?q?=E9=97=B4=E6=BB=91=E5=8A=A8=E5=AF=BC=E8=87=B4=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E6=9C=88=E5=8E=86=E9=94=99=E4=BD=8D=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plus/rua/project/ui/CalendarMonthView.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt index 8a62875..d4cd064 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -170,11 +170,6 @@ fun CalendarMonthView( var isMenuExpanded by remember { mutableStateOf(false) } var showDatePicker by remember { mutableStateOf(false) } - // 视图切换时自动关闭菜单 - LaunchedEffect(isYearView) { - isMenuExpanded = false - } - val pagerState = rememberPagerState(initialPage = START_PAGE, pageCount = { Int.MAX_VALUE }) // 年视图分页器 @@ -183,6 +178,14 @@ fun CalendarMonthView( pageCount = { Int.MAX_VALUE } ) + // 视图切换时自动关闭菜单并重置年视图 Pager + LaunchedEffect(isYearView) { + isMenuExpanded = false + if (isYearView && yearPagerState.currentPage != START_PAGE) { + yearPagerState.scrollToPage(START_PAGE) + } + } + // 年视图翻页时同步 yearViewYear(跟踪 settled page 差值) LaunchedEffect(yearPagerState) { var lastSettledPage = yearPagerState.currentPage @@ -299,7 +302,7 @@ fun CalendarMonthView( modifier = Modifier .clipToBounds() .sharedBounds( - sharedContentState = rememberSharedContentState(key = "month_grid_$currentMonth"), + sharedContentState = rememberSharedContentState(key = "month_grid_${currentYear}_$currentMonth"), animatedVisibilityScope = this@AnimatedContent, boundsTransform = { _, _ -> spring(stiffness = Spring.StiffnessMediumLow, dampingRatio = Spring.DampingRatioNoBouncy) @@ -338,6 +341,7 @@ fun CalendarMonthView( ) HorizontalPager( state = yearPagerState, + userScrollEnabled = (this@AnimatedContent.transition.currentState == this@AnimatedContent.transition.targetState), beyondViewportPageCount = 0, flingBehavior = PagerDefaults.flingBehavior(state = yearPagerState), modifier = Modifier @@ -366,7 +370,7 @@ fun CalendarMonthView( }, monthModifier = { month -> Modifier.sharedBounds( - sharedContentState = rememberSharedContentState(key = "month_grid_$month"), + sharedContentState = rememberSharedContentState(key = "month_grid_${pageYear}_$month"), animatedVisibilityScope = this@AnimatedContent, boundsTransform = { _, _ -> spring(stiffness = Spring.StiffnessMediumLow, dampingRatio = Spring.DampingRatioNoBouncy)