选中态:今天=实心填充,非今天=描边圆,角标置顶不再被遮挡
之前所有选中态都是实心圆,描边圆只用于"今天未选中"。 现改为:今天+选中=primaryContainer 实心填充,普通日期+选中=primary 描边圆, 今天未选中维持细描边。 角标加 zIndex(1f) 提到最上,padding 收紧到 top=1/end=2 紧贴右上角方形空白, 配合描边圆改造,休/班角标在选中态下不再被圆形覆盖。
This commit is contained in:
parent
aa223db519
commit
71a3cbc62a
@ -32,6 +32,7 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.compose.ui.zIndex
|
||||||
import com.tyme.solar.SolarDay
|
import com.tyme.solar.SolarDay
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
|
|
||||||
@ -84,24 +85,35 @@ fun DayCell(
|
|||||||
) { state ->
|
) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.onPrimaryContainer
|
DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
DayCellState.SELECTED -> MaterialTheme.colorScheme.onPrimary
|
DayCellState.SELECTED -> MaterialTheme.colorScheme.primary
|
||||||
DayCellState.TODAY -> MaterialTheme.colorScheme.primary
|
DayCellState.TODAY -> MaterialTheme.colorScheme.primary
|
||||||
DayCellState.OTHER_MONTH -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
DayCellState.OTHER_MONTH -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
DayCellState.NORMAL -> MaterialTheme.colorScheme.onSurface
|
DayCellState.NORMAL -> MaterialTheme.colorScheme.onSurface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val selectedColor by transition.animateColor(
|
// 选中今天:实心填充 primaryContainer;其他状态不填充。
|
||||||
|
val selectedFillColor by transition.animateColor(
|
||||||
transitionSpec = { tween(250, easing = FastOutSlowInEasing) },
|
transitionSpec = { tween(250, easing = FastOutSlowInEasing) },
|
||||||
label = "selectedColor"
|
label = "selectedFillColor"
|
||||||
) { state ->
|
) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.primaryContainer
|
DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.primaryContainer
|
||||||
DayCellState.SELECTED -> MaterialTheme.colorScheme.primary
|
|
||||||
else -> Color.Transparent
|
else -> Color.Transparent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 选中非今天:绘制描边圆,避免遮挡右上角角标。
|
||||||
|
val selectedOutlineAlpha by transition.animateFloat(
|
||||||
|
transitionSpec = { tween(250, easing = FastOutSlowInEasing) },
|
||||||
|
label = "selectedOutlineAlpha"
|
||||||
|
) { state ->
|
||||||
|
when (state) {
|
||||||
|
DayCellState.SELECTED -> 1f
|
||||||
|
else -> 0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val borderAlpha by transition.animateFloat(
|
val borderAlpha by transition.animateFloat(
|
||||||
transitionSpec = { tween(250, easing = FastOutSlowInEasing) },
|
transitionSpec = { tween(250, easing = FastOutSlowInEasing) },
|
||||||
label = "borderAlpha"
|
label = "borderAlpha"
|
||||||
@ -113,6 +125,7 @@ fun DayCell(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val todayBorderColor = MaterialTheme.colorScheme.primary
|
val todayBorderColor = MaterialTheme.colorScheme.primary
|
||||||
|
val selectedOutlineColor = MaterialTheme.colorScheme.primary
|
||||||
|
|
||||||
data class DayAnnotation(val text: String, val isHighlight: Boolean)
|
data class DayAnnotation(val text: String, val isHighlight: Boolean)
|
||||||
|
|
||||||
@ -163,7 +176,7 @@ fun DayCell(
|
|||||||
if (annotation.isHighlight) {
|
if (annotation.isHighlight) {
|
||||||
when (state) {
|
when (state) {
|
||||||
DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.85f)
|
DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.85f)
|
||||||
DayCellState.SELECTED -> MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.85f)
|
DayCellState.SELECTED -> MaterialTheme.colorScheme.error.copy(alpha = 0.7f)
|
||||||
DayCellState.TODAY -> MaterialTheme.colorScheme.primary
|
DayCellState.TODAY -> MaterialTheme.colorScheme.primary
|
||||||
DayCellState.OTHER_MONTH -> MaterialTheme.colorScheme.error.copy(alpha = 0.35f)
|
DayCellState.OTHER_MONTH -> MaterialTheme.colorScheme.error.copy(alpha = 0.35f)
|
||||||
DayCellState.NORMAL -> MaterialTheme.colorScheme.error.copy(alpha = 0.7f)
|
DayCellState.NORMAL -> MaterialTheme.colorScheme.error.copy(alpha = 0.7f)
|
||||||
@ -171,7 +184,7 @@ fun DayCell(
|
|||||||
} else {
|
} else {
|
||||||
when (state) {
|
when (state) {
|
||||||
DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f)
|
DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f)
|
||||||
DayCellState.SELECTED -> MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.7f)
|
DayCellState.SELECTED -> MaterialTheme.colorScheme.primary.copy(alpha = 0.7f)
|
||||||
DayCellState.TODAY -> MaterialTheme.colorScheme.primary.copy(alpha = 0.6f)
|
DayCellState.TODAY -> MaterialTheme.colorScheme.primary.copy(alpha = 0.6f)
|
||||||
DayCellState.OTHER_MONTH -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.26f)
|
DayCellState.OTHER_MONTH -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.26f)
|
||||||
DayCellState.NORMAL -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f)
|
DayCellState.NORMAL -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f)
|
||||||
@ -198,19 +211,29 @@ fun DayCell(
|
|||||||
}
|
}
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.drawBehind {
|
.drawBehind {
|
||||||
if (revealProgress > 0f) {
|
val maxRadius = size.minDimension / 2f
|
||||||
val maxRadius = size.minDimension / 2f
|
val center = Offset(size.width / 2f, size.height / 2f)
|
||||||
|
if (revealProgress > 0f && selectedFillColor.alpha > 0f) {
|
||||||
drawCircle(
|
drawCircle(
|
||||||
color = selectedColor,
|
color = selectedFillColor,
|
||||||
radius = revealProgress * maxRadius,
|
radius = revealProgress * maxRadius,
|
||||||
center = Offset(size.width / 2f, size.height / 2f)
|
center = center
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (revealProgress > 0f && selectedOutlineAlpha > 0f) {
|
||||||
|
val strokePx = 1.5.dp.toPx()
|
||||||
|
drawCircle(
|
||||||
|
color = selectedOutlineColor.copy(alpha = selectedOutlineAlpha),
|
||||||
|
radius = revealProgress * maxRadius - strokePx / 2f,
|
||||||
|
center = center,
|
||||||
|
style = Stroke(width = strokePx)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (borderAlpha > 0f) {
|
if (borderAlpha > 0f) {
|
||||||
drawCircle(
|
drawCircle(
|
||||||
color = todayBorderColor.copy(alpha = borderAlpha.coerceAtMost(1f)),
|
color = todayBorderColor.copy(alpha = borderAlpha.coerceAtMost(1f)),
|
||||||
radius = size.minDimension / 2f,
|
radius = maxRadius,
|
||||||
center = Offset(size.width / 2f, size.height / 2f),
|
center = center,
|
||||||
style = Stroke(width = borderAlpha.coerceAtMost(1.5f) * 1.5.dp.toPx())
|
style = Stroke(width = borderAlpha.coerceAtMost(1.5f) * 1.5.dp.toPx())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -247,7 +270,8 @@ fun DayCell(
|
|||||||
lineHeight = 9.sp,
|
lineHeight = 9.sp,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.TopEnd)
|
.align(Alignment.TopEnd)
|
||||||
.padding(top = 2.dp, end = 4.dp)
|
.zIndex(1f)
|
||||||
|
.padding(top = 1.dp, end = 2.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user