优化动画细节

This commit is contained in:
zzh 2025-11-27 12:45:22 +08:00
parent 2c5afcfd6c
commit 9945bee5d2

View File

@ -592,7 +592,7 @@ fun WeatherCard(weatherInfo: WeatherInfo, isLoading: Boolean) {
label = "gradient" label = "gradient"
) )
// 根据天气状况决定背景颜色 - 增加颜色差异让流动更明显 // 根据天气状况决定背景颜色
val colors = if (isLoading) { val colors = if (isLoading) {
listOf( listOf(
Color(0xFF2C3E50).copy(alpha = 0.6f), Color(0xFF2C3E50).copy(alpha = 0.6f),
@ -601,12 +601,12 @@ fun WeatherCard(weatherInfo: WeatherInfo, isLoading: Boolean) {
) )
} else { } else {
when { when {
// 晴天:橙色流动 // 晴天:橙色流动
weatherInfo.weather.contains("") -> weatherInfo.weather.contains("") ->
listOf( listOf(
Color(0xFFB8450A).copy(alpha = 0.55f), Color(0xFF8B3000).copy(alpha = 0.65f),
Color(0xFFC06000).copy(alpha = 0.55f), Color(0xFF9A4500).copy(alpha = 0.65f),
Color(0xFFB8450A).copy(alpha = 0.55f) Color(0xFF8B3000).copy(alpha = 0.65f)
) )
// 雨天:深紫深蓝流动 // 雨天:深紫深蓝流动
weatherInfo.weather.contains("") -> weatherInfo.weather.contains("") ->
@ -644,7 +644,7 @@ fun WeatherCard(weatherInfo: WeatherInfo, isLoading: Boolean) {
start = Offset(offsetAnim, offsetAnim), start = Offset(offsetAnim, offsetAnim),
end = Offset(offsetAnim + 500f, offsetAnim + 500f) end = Offset(offsetAnim + 500f, offsetAnim + 500f)
) )
Box( Box(
modifier = Modifier modifier = Modifier
.clip(RoundedCornerShape(16.dp)) .clip(RoundedCornerShape(16.dp))
@ -1628,12 +1628,13 @@ fun WeatherEffectLayer(weather: String, modifier: Modifier = Modifier) {
label = "sun_rotation" label = "sun_rotation"
) )
// 雨雪下落动画 // 雨雪下落动画 - 使用更长的周期避免明显停顿
val dropOffset by infiniteTransition.animateFloat( val dropOffset by infiniteTransition.animateFloat(
initialValue = 0f, initialValue = 0f,
targetValue = 1f, targetValue = 1f,
animationSpec = infiniteRepeatable( animationSpec = infiniteRepeatable(
animation = tween(1500, easing = LinearEasing) animation = tween(8000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
), ),
label = "drop_offset" label = "drop_offset"
) )
@ -1688,18 +1689,21 @@ fun WeatherEffectLayer(weather: String, modifier: Modifier = Modifier) {
// 雨天:绘制下落的雨滴 // 雨天:绘制下落的雨滴
weather.contains("") -> { weather.contains("") -> {
val dropCount = 8 val dropCount = 20
val dropLength = 8.dp.toPx() val dropLength = 10.dp.toPx()
for (i in 0 until dropCount) { for (i in 0 until dropCount) {
val x = (i * width / dropCount) + (i * 17 % 30) // 使用不同的起始位置和速度让雨滴错开
val startY = (i * 29 % height.toInt()).toFloat() val xOffset = (i * 37 % 100) / 100f
val currentY = (startY + dropOffset * height) % height val x = width * xOffset
val speedFactor = 3f + (i % 5) * 0.5f // 更快的速度,一个周期内多次循环
val startOffset = (i * 73 % 100) / 100f // 不同起始位置
val currentY = ((startOffset + dropOffset * speedFactor) % 1f) * height
drawLine( drawLine(
color = Color.White.copy(alpha = 0.3f), color = Color.White.copy(alpha = 0.35f),
start = Offset(x, currentY), start = Offset(x, currentY),
end = Offset(x - 2.dp.toPx(), currentY + dropLength), end = Offset(x, currentY + dropLength), // 垂直下落
strokeWidth = 1.5f.dp.toPx() strokeWidth = 1.5f.dp.toPx()
) )
} }
@ -1707,12 +1711,15 @@ fun WeatherEffectLayer(weather: String, modifier: Modifier = Modifier) {
// 雪天:绘制飘落的雪花(圆点) // 雪天:绘制飘落的雪花(圆点)
weather.contains("") -> { weather.contains("") -> {
val snowCount = 8 val snowCount = 18
for (i in 0 until snowCount) { for (i in 0 until snowCount) {
val x = (i * width / snowCount) + (i * 23 % 40) // 使用不同的起始位置和速度让雪花错开
val startY = (i * 41 % height.toInt()).toFloat() val xOffset = (i * 41 % 100) / 100f
val currentY = (startY + dropOffset * height * 0.5f) % height val x = width * xOffset
val speedFactor = 1.5f + (i % 4) * 0.3f // 雪花下落更慢
val startOffset = (i * 67 % 100) / 100f
val currentY = ((startOffset + dropOffset * speedFactor) % 1f) * height
drawCircle( drawCircle(
color = Color.White.copy(alpha = 0.5f), color = Color.White.copy(alpha = 0.5f),