From 418b97baed43e4db0b96282f610350fd09da757f Mon Sep 17 00:00:00 2001 From: meyou <2636699780@qq.com> Date: Sat, 16 May 2026 15:32:26 +0800 Subject: [PATCH] Fix week number baseline alignment and collapsed state today jump - MonthHeader: align week number text baseline with month text (Bottom) - WeekPager: scroll to selectedDate's week when it changes externally, fixing the case where clicking "back to today" in collapsed state didn't navigate the week pager to the current week --- .../kotlin/plus/rua/project/ui/MonthHeader.kt | 2 +- .../commonMain/kotlin/plus/rua/project/ui/WeekPager.kt | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt index c8b42b7..2b8f151 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/MonthHeader.kt @@ -41,7 +41,7 @@ fun MonthHeader( .fillMaxWidth() .padding(vertical = 14.dp, horizontal = 12.dp) .then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier), - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.Bottom ) { AnimatedContent( targetState = Pair(year, month), 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 6173edb..97f7a13 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt @@ -16,6 +16,7 @@ import androidx.compose.ui.unit.dp import kotlinx.coroutines.flow.drop import kotlinx.datetime.DatePeriod import kotlinx.datetime.LocalDate +import kotlinx.datetime.daysUntil import kotlinx.datetime.plus import kotlin.math.abs @@ -42,6 +43,15 @@ fun WeekPager( pageCount = { Int.MAX_VALUE } ) + // selectedDate 外部变更(如点击回到今天)时,滚动到对应周 + LaunchedEffect(selectedDate) { + val targetMonday = selectedDate.toWeekMonday() + val targetPage = START_PAGE + (initialWeekMonday.daysUntil(targetMonday) / 7) + if (pagerState.currentPage != targetPage) { + pagerState.animateScrollToPage(targetPage) + } + } + LaunchedEffect(pagerState) { snapshotFlow { pagerState.settledPage }.drop(1).collect { page -> val weekMonday = pageToWeekMonday(page, initialWeekMonday)