refactor: MenuItem 和 ToolItem 统一使用 Card(onClick)

This commit is contained in:
xfy 2026-06-01 13:18:27 +08:00
parent 6446d6636e
commit a8717dec7d
3 changed files with 14 additions and 15 deletions

View File

@ -77,3 +77,4 @@ CalendarMonthView ← top-level screen (MonthHeader + WeekdayHeader + p
- Public `@Composable` functions require KDoc per `COMMENTS.md` - Public `@Composable` functions require KDoc per `COMMENTS.md`
- `Modifier` parameter always last in composable signatures - `Modifier` parameter always last in composable signatures
- Callback parameters use `on` prefix (`onDateClick`, `onMonthChanged`) - Callback parameters use `on` prefix (`onDateClick`, `onMonthChanged`)
- **Clickable list items:** Use `Card(onClick = ...)` with `CardDefaults.cardElevation(defaultElevation = 0.dp)` instead of `Modifier.clickable()` on `Box`/`Row`. This ensures consistent Material 3 press-state feedback (ripple + background color change) across all interactive list/menu items. See `LicensesScreen`, `ToolsScreen`, and `CalendarMonthView.MenuItem` for reference.

View File

@ -633,23 +633,22 @@ private fun MenuItem(
onClick: () -> Unit, onClick: () -> Unit,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
Box( Card(
modifier = modifier onClick = onClick,
.fillMaxWidth() shape = RoundedCornerShape(8.dp),
.clickable(onClick = onClick) colors = CardDefaults.cardColors(
.then( containerColor = if (selected) MaterialTheme.colorScheme.primaryContainer
if (selected) Modifier.background( else MaterialTheme.colorScheme.surfaceContainerHigh
MaterialTheme.colorScheme.primaryContainer, ),
RoundedCornerShape(8.dp) elevation = CardDefaults.cardElevation(defaultElevation = 0.dp),
) else Modifier modifier = modifier.fillMaxWidth()
)
.padding(horizontal = 16.dp, vertical = 12.dp)
) { ) {
Text( Text(
text = text, text = text,
color = if (selected) MaterialTheme.colorScheme.onPrimaryContainer color = if (selected) MaterialTheme.colorScheme.onPrimaryContainer
else MaterialTheme.colorScheme.onSurface, else MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.bodyLarge style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp)
) )
} }
} }

View File

@ -93,14 +93,13 @@ private fun ToolItem(
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
Card( Card(
onClick = onClick,
shape = RoundedCornerShape(16.dp), shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors( colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh containerColor = MaterialTheme.colorScheme.surfaceContainerHigh
), ),
elevation = CardDefaults.cardElevation(defaultElevation = 0.dp), elevation = CardDefaults.cardElevation(defaultElevation = 0.dp),
modifier = modifier modifier = modifier.fillMaxWidth()
.fillMaxWidth()
.clickable(onClick = onClick)
) { ) {
Text( Text(
text = title, text = title,