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))
AnimatedVisibility(
visible = year != currentYear,
enter = fadeIn(tween(200)) + scaleIn(spring(stiffness = Spring.StiffnessMedium), initialScale = 0.7f),
exit = fadeOut(tween(150)) + scaleOut(targetScale = 0.8f),
label = "this_year_button_visibility"
) {
val showThisYear = year != currentYear
val thisYearAlpha by androidx.compose.animation.core.animateFloatAsState(
targetValue = if (showThisYear) 1f else 0f,
animationSpec = tween(200),
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(
onClick = { onYearChange(currentYear) },
onClick = { if (showThisYear) onYearChange(currentYear) },
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 = "今年",
@ -428,7 +438,6 @@ fun YearHeader(
)
}
}
}
AnimatedContent(
targetState = year,
label = "year_header_lunar",