fix(ui): eliminate year header layout jitter when showing this year button

This commit is contained in:
xfy 2026-07-24 13:20:56 +08:00
parent 0703be68b4
commit adc149c462

View File

@ -408,25 +408,34 @@ fun YearHeader(
) )
} }
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
AnimatedVisibility( val showThisYear = year != currentYear
visible = year != currentYear, val thisYearAlpha by androidx.compose.animation.core.animateFloatAsState(
enter = fadeIn(tween(200)) + scaleIn(spring(stiffness = Spring.StiffnessMedium), initialScale = 0.7f), targetValue = if (showThisYear) 1f else 0f,
exit = fadeOut(tween(150)) + scaleOut(targetScale = 0.8f), animationSpec = tween(200),
label = "this_year_button_visibility" label = "this_year_alpha"
) { )
Surface( val thisYearScale by androidx.compose.animation.core.animateFloatAsState(
onClick = { onYearChange(currentYear) }, targetValue = if (showThisYear) 1f else 0.8f,
shape = RoundedCornerShape(12.dp), animationSpec = spring(stiffness = Spring.StiffnessMedium),
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.4f) label = "this_year_scale"
) { )
Text( Surface(
text = "今年", onClick = { if (showThisYear) onYearChange(currentYear) },
color = MaterialTheme.colorScheme.primary, shape = RoundedCornerShape(12.dp),
fontSize = 14.sp, color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.4f),
fontWeight = FontWeight.Medium, modifier = Modifier.graphicsLayer {
modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp) alpha = thisYearAlpha
) scaleX = thisYearScale
scaleY = thisYearScale
} }
) {
Text(
text = "今年",
color = MaterialTheme.colorScheme.primary,
fontSize = 14.sp,
fontWeight = FontWeight.Medium,
modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp)
)
} }
} }
AnimatedContent( AnimatedContent(