点击月份标题跳转到今天
This commit is contained in:
parent
fcad070800
commit
b65856a4ae
@ -27,6 +27,7 @@ import kotlinx.datetime.TimeZone
|
|||||||
import kotlinx.datetime.number
|
import kotlinx.datetime.number
|
||||||
import kotlinx.datetime.plus
|
import kotlinx.datetime.plus
|
||||||
import kotlinx.datetime.todayIn
|
import kotlinx.datetime.todayIn
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import plus.rua.project.CalendarViewModel
|
import plus.rua.project.CalendarViewModel
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.time.Clock
|
import kotlin.time.Clock
|
||||||
@ -144,6 +145,17 @@ fun CalendarMonthView(
|
|||||||
year = currentYear,
|
year = currentYear,
|
||||||
month = currentMonth,
|
month = currentMonth,
|
||||||
weekNumber = viewModel.getIsoWeekNumber(viewModel.selectedDate),
|
weekNumber = viewModel.getIsoWeekNumber(viewModel.selectedDate),
|
||||||
|
onClick = {
|
||||||
|
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 ->
|
modifier = Modifier.onSizeChanged { size ->
|
||||||
monthHeaderHeightPx = size.height
|
monthHeaderHeightPx = size.height
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import androidx.compose.animation.fadeOut
|
|||||||
import androidx.compose.animation.slideInVertically
|
import androidx.compose.animation.slideInVertically
|
||||||
import androidx.compose.animation.slideOutVertically
|
import androidx.compose.animation.slideOutVertically
|
||||||
import androidx.compose.animation.togetherWith
|
import androidx.compose.animation.togetherWith
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
@ -32,12 +33,14 @@ fun MonthHeader(
|
|||||||
year: Int,
|
year: Int,
|
||||||
month: Int,
|
month: Int,
|
||||||
weekNumber: Int,
|
weekNumber: Int,
|
||||||
|
onClick: (() -> Unit)? = null,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(vertical = 14.dp, horizontal = 12.dp),
|
.padding(vertical = 14.dp, horizontal = 12.dp)
|
||||||
|
.then(if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
AnimatedContent(
|
AnimatedContent(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user