Fix style issues in MonthHeader and CalendarMonthView

Replace hardcoded padding values with constants, use Spacer instead of
space character for spacing, remove fontSize override on bodySmall, and
fix WeekdayHeader modifier order (padding before onSizeChanged).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-05-15 10:18:52 +08:00
parent 2ba3cc5d42
commit b794601134
2 changed files with 11 additions and 9 deletions

View File

@ -32,6 +32,7 @@ import plus.rua.project.CalendarViewModel
private const val START_PAGE = Int.MAX_VALUE / 2
private const val ROW_PADDING_DP = 4
private const val HORIZONTAL_PADDING_DP = 16
/**
* 日历主界面包含月/周视图切换和折叠动画
@ -89,8 +90,8 @@ fun CalendarMonthView(
// 预估行高DayCell aspectRatio=1宽度 = (screenWidth - horizontalPadding) / 7
// 加上 Row 的 vertical padding (4dp × 2)
val estimatedRowHeightPx = if (screenWidthPx > 0) {
val cellWidth = (screenWidthPx - with(density) { 32.dp.toPx() }) / 7
val rowPadding = with(density) { 8.dp.toPx() }
val cellWidth = (screenWidthPx - with(density) { (HORIZONTAL_PADDING_DP * 2).dp.toPx() }) / 7
val rowPadding = with(density) { (ROW_PADDING_DP * 2).dp.toPx() }
(cellWidth + rowPadding).toInt()
} else 0
@ -130,7 +131,7 @@ fun CalendarMonthView(
screenHeightPx = size.height
}
) {
Column(modifier = Modifier.padding(horizontal = 16.dp)) {
Column(modifier = Modifier.padding(horizontal = HORIZONTAL_PADDING_DP.dp)) {
MonthHeader(
year = currentYear,
month = currentMonth,
@ -140,9 +141,9 @@ fun CalendarMonthView(
}
)
WeekdayHeader(
modifier = Modifier.fillMaxWidth().onSizeChanged { size ->
modifier = Modifier.fillMaxWidth().padding(bottom = ROW_PADDING_DP.dp).onSizeChanged { size ->
weekdayHeaderHeightPx = size.height
}.padding(bottom = ROW_PADDING_DP.dp)
}
)
// 完全折叠且无动画时显示 WeekPager否则显示 CalendarPager含下拉恢复过程
if (viewModel.isCollapsed && viewModel.collapseProgress >= 1f) {

View File

@ -1,15 +1,16 @@
package plus.rua.project.ui
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
/**
* 月份标题栏显示"年月"文字和 ISO 周号
@ -36,10 +37,10 @@ fun MonthHeader(
text = "${year}${month}",
style = MaterialTheme.typography.titleLarge
)
Spacer(modifier = Modifier.width(6.dp))
Text(
text = "${weekNumber}",
style = MaterialTheme.typography.bodySmall,
fontSize = 13.sp
text = "${weekNumber}",
style = MaterialTheme.typography.bodySmall
)
}
}