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
This commit is contained in:
meyou 2026-05-16 15:32:26 +08:00
parent 055738220c
commit 418b97baed
2 changed files with 11 additions and 1 deletions

View File

@ -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),

View File

@ -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)