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,16 +408,26 @@ 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"
) { )
val thisYearScale by androidx.compose.animation.core.animateFloatAsState(
targetValue = if (showThisYear) 1f else 0.8f,
animationSpec = spring(stiffness = Spring.StiffnessMedium),
label = "this_year_scale"
)
Surface( Surface(
onClick = { onYearChange(currentYear) }, onClick = { if (showThisYear) onYearChange(currentYear) },
shape = RoundedCornerShape(12.dp), shape = RoundedCornerShape(12.dp),
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.4f) color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.4f),
modifier = Modifier.graphicsLayer {
alpha = thisYearAlpha
scaleX = thisYearScale
scaleY = thisYearScale
}
) { ) {
Text( Text(
text = "今年", text = "今年",
@ -428,7 +438,6 @@ fun YearHeader(
) )
} }
} }
}
AnimatedContent( AnimatedContent(
targetState = year, targetState = year,
label = "year_header_lunar", label = "year_header_lunar",