Skip to content

Commit 349916f

Browse files
author
zhujiang2
committed
新增雷雨动画
1 parent 7c5e286 commit 349916f

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.zui.animate
2+
3+
import androidx.compose.animation.core.RepeatMode
4+
import androidx.compose.animation.core.animateFloat
5+
import androidx.compose.animation.core.infiniteRepeatable
6+
import androidx.compose.animation.core.rememberInfiniteTransition
7+
import androidx.compose.animation.core.tween
8+
import androidx.compose.foundation.Image
9+
import androidx.compose.foundation.layout.Box
10+
import androidx.compose.foundation.layout.offset
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.runtime.getValue
13+
import androidx.compose.ui.Alignment
14+
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.platform.LocalConfiguration
16+
import androidx.compose.ui.res.painterResource
17+
import androidx.compose.ui.unit.dp
18+
19+
@Composable
20+
fun Thunder(
21+
modifier: Modifier = Modifier,
22+
durationMillis1: Int = 500,
23+
durationMillis2: Int = 1000
24+
) {
25+
val screenWidthDp = LocalConfiguration.current.screenWidthDp
26+
val transition = rememberInfiniteTransition(label = "")
27+
val alpha by transition.animateFloat(
28+
initialValue = 0f,
29+
targetValue = 1f,
30+
animationSpec = infiniteRepeatable(
31+
tween(durationMillis1),
32+
RepeatMode.Reverse
33+
), label = ""
34+
)
35+
val alpha2 by transition.animateFloat(
36+
initialValue = 1f,
37+
targetValue = 0f,
38+
animationSpec = infiniteRepeatable(
39+
tween(durationMillis2),
40+
RepeatMode.Reverse
41+
), label = ""
42+
)
43+
Box(modifier = modifier) {
44+
Image(
45+
modifier = Modifier.offset((screenWidthDp / 20).dp, 0.dp),
46+
painter = painterResource(id = R.drawable.ic_thunder1), contentDescription = "",
47+
alpha = alpha
48+
)
49+
Image(
50+
modifier = Modifier.align(Alignment.TopCenter),
51+
painter = painterResource(id = R.drawable.ic_thunder2), contentDescription = "",
52+
alpha = alpha
53+
)
54+
Image(
55+
modifier = Modifier.align(Alignment.TopEnd),
56+
painter = painterResource(id = R.drawable.ic_thunder3), contentDescription = "",
57+
alpha = alpha2
58+
)
59+
Image(
60+
modifier = Modifier.offset((screenWidthDp / 18).dp, 0.dp),
61+
painter = painterResource(id = R.drawable.ic_thunder4), contentDescription = "",
62+
alpha = alpha2
63+
)
64+
}
65+
}

animate/src/main/java/com/zui/animate/WeatherBackground.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ object WeatherAnimateType {
2424
// 暴雨
2525
const val RAINSTORM = 24
2626

27+
// 雷雨
28+
const val THUNDER_RAIN = 25
29+
2730
// 小雪
2831
const val LIGHT_SNOW = 31
2932

@@ -69,6 +72,11 @@ fun WeatherBackground(
6972
Rain(modifier, Rains.RAINSTORM)
7073
}
7174

75+
WeatherAnimateType.THUNDER_RAIN -> {
76+
Rain(modifier, Rains.MODERATE_RAIN)
77+
Thunder(modifier)
78+
}
79+
7280
WeatherAnimateType.LIGHT_SNOW -> {
7381
Snow(modifier, Snows.LIGHT_SNOW)
7482
}
@@ -101,10 +109,11 @@ private fun getWeatherAnimateType(weather: String?): Int? {
101109
"101", "102", "103", "151", "152", "153", "104", "154", "200", "201", "202", "203", "204", "205", "206", "207", "208",
102110
"209", "210", "211", "212", "213" -> WeatherAnimateType.CLOUDY
103111

104-
"300", "301", "302", "303", "304", "305", "308", "309" -> WeatherAnimateType.LIGHT_RAIN
112+
"300", "301", "305", "308", "309" -> WeatherAnimateType.LIGHT_RAIN
105113
"306", "350", "351", "399" -> WeatherAnimateType.MODERATE_RAIN
106114
"307" -> WeatherAnimateType.HEAVY_RAIN
107115
"310", "311", "312" -> WeatherAnimateType.RAINSTORM
116+
"302", "303", "304" -> WeatherAnimateType.THUNDER_RAIN
108117

109118
"400", "407", "408", "456", "457", "499", "404", "405", "406", "313" -> WeatherAnimateType.LIGHT_SNOW
110119
"401", "409" -> WeatherAnimateType.MODERATE_SNOW
9.69 KB
Loading
21.1 KB
Loading
21.2 KB
Loading
9.81 KB
Loading

0 commit comments

Comments
 (0)