修复点击"今天"按钮无动画:scrollToPage 改为 animateScrollToPage

LaunchedEffect(selectedDate) 用无动画的 scrollToPage 抢先跳转,
导致 onToday 里的 animateScrollToPage 被取消。统一由
LaunchedEffect 处理滚动,onToday 只需 selectDate。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-05-18 15:43:09 +08:00
parent 917ba2125f
commit 996d8c104f

View File

@ -132,7 +132,7 @@ fun CalendarMonthView(
today.year, today.month.number
)
if (targetPage != pagerState.currentPage) {
pagerState.scrollToPage(targetPage)
pagerState.animateScrollToPage(targetPage)
}
}
@ -239,14 +239,6 @@ fun CalendarMonthView(
showToday = viewModel.selectedDate != today,
onToday = {
viewModel.selectDate(today)
@Suppress("DEPRECATION") // monthNumber 无替代 API
val targetPage = yearMonthToPage(
today.year, today.month.number,
today.year, today.month.number
)
if (targetPage != pagerState.currentPage) {
coroutineScope.launch { pagerState.animateScrollToPage(targetPage) }
}
},
modifier = Modifier.onSizeChanged { size ->
monthHeaderHeightPx = size.height