Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 38f14f5

Browse files
committed
fix sun animation
1 parent 445b9d1 commit 38f14f5

File tree

3 files changed

+313
-137
lines changed

3 files changed

+313
-137
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package dev.baseio.composeplayground
2+
3+
import androidx.compose.animation.core.*
4+
import androidx.compose.foundation.Image
5+
import androidx.compose.foundation.layout.Box
6+
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.foundation.layout.offset
8+
import androidx.compose.runtime.*
9+
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.draw.scale
11+
import androidx.compose.ui.graphics.graphicsLayer
12+
import androidx.compose.ui.platform.LocalConfiguration
13+
import androidx.compose.ui.platform.LocalDensity
14+
import androidx.compose.ui.res.painterResource
15+
import androidx.compose.ui.unit.IntOffset
16+
import androidx.compose.ui.unit.dp
17+
import dev.baseio.composeplayground.ui.animations.pulltorefresh.NightSky
18+
19+
@Composable
20+
fun AnimateStarAsState() {
21+
22+
val centerX =
23+
LocalDensity.current.run { LocalConfiguration.current.screenWidthDp.dp.toPx().div(2) }
24+
val centerY =
25+
LocalDensity.current.run { LocalConfiguration.current.screenHeightDp.dp.toPx().div(2) }
26+
27+
val infiniteTransition = rememberInfiniteTransition()
28+
29+
val rotationY by infiniteTransition.animateFloat(
30+
initialValue = 0f,
31+
targetValue = 1f,
32+
animationSpec = InfiniteRepeatableSpec(keyframes {
33+
durationMillis = 5000
34+
0f at 0 with LinearEasing
35+
30f at 2500 with LinearEasing
36+
45f at 3500 with LinearEasing
37+
65f at 5000 with LinearEasing
38+
}, repeatMode = RepeatMode.Restart)
39+
)
40+
41+
val rotationZ by infiniteTransition.animateFloat(
42+
initialValue = 0f,
43+
targetValue = 1f,
44+
animationSpec = InfiniteRepeatableSpec(keyframes {
45+
durationMillis = 5000
46+
0f at 0 with LinearEasing
47+
-10f at 2500 with LinearEasing
48+
-12f at 3500 with LinearEasing
49+
-18f at 5000 with LinearEasing
50+
}, repeatMode = RepeatMode.Restart)
51+
)
52+
53+
val airplaneScale by infiniteTransition.animateFloat(
54+
initialValue = 0f,
55+
targetValue = 1f,
56+
animationSpec = InfiniteRepeatableSpec(keyframes {
57+
durationMillis = 5000
58+
1.5f at 0 with LinearEasing
59+
1f at 2500 with LinearEasing
60+
0.8f at 5000 with LinearEasing
61+
}, repeatMode = RepeatMode.Restart)
62+
)
63+
64+
val airplaneX by infiniteTransition.animateFloat(0f, 1f, InfiniteRepeatableSpec(keyframes {
65+
durationMillis = 5000
66+
0f at 0 with LinearEasing
67+
centerX.div(4) at 0 with LinearEasing
68+
centerX.div(2) at 2500 with LinearEasing
69+
centerX.times(2.5f) at 5000 with LinearEasing
70+
}, repeatMode = RepeatMode.Restart))
71+
72+
val airplaneY by infiniteTransition.animateFloat(0f, 1f, InfiniteRepeatableSpec(keyframes {
73+
durationMillis = 5000
74+
centerY at 0 with LinearEasing
75+
centerY.times(0.95f) at 1500 with LinearEasing
76+
centerY.times(0.8f) at 2500 with LinearEasing
77+
centerY.times(0.5f) at 3800 with LinearEasing
78+
centerY.times(0.0f) at 5000 with LinearEasing
79+
}, repeatMode = RepeatMode.Restart))
80+
81+
82+
Box(modifier = Modifier.fillMaxSize()) {
83+
84+
NightSky(height = centerY.times(2))
85+
Image(
86+
painter = painterResource(id = R.drawable.airplane),
87+
contentDescription = null, modifier = Modifier
88+
.offset {
89+
IntOffset(
90+
airplaneX
91+
.toInt(),
92+
airplaneY
93+
.toInt()
94+
)
95+
}
96+
.scale(airplaneScale)
97+
.graphicsLayer(rotationY = rotationY, rotationZ = rotationZ)
98+
)
99+
100+
}
101+
102+
103+
}

‎app/src/main/java/dev/baseio/composeplayground/MainActivity.kt‎

Lines changed: 92 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.activity.compose.setContent
1010
import androidx.compose.foundation.layout.*
1111
import androidx.compose.material.MaterialTheme
1212
import androidx.compose.material.Surface
13+
import androidx.compose.runtime.Composable
1314
import androidx.compose.ui.Alignment
1415
import androidx.compose.ui.Modifier
1516
import androidx.compose.ui.unit.dp
@@ -43,95 +44,101 @@ class MainActivity : ComponentActivity() {
4344
MaterialTheme() {
4445
ProvideWindowInsets() {
4546
Surface(color = MaterialTheme.colors.background) {
46-
val pagerState = rememberPagerState()
47-
Box(
48-
modifier = Modifier
49-
.fillMaxSize()
50-
) {
51-
HorizontalPager(
52-
modifier = Modifier.fillMaxSize(),
53-
count = 15, state = pagerState,
54-
) { page ->
55-
// Our page content
56-
when (page) {
57-
4 -> {
58-
PullToRefreshOne()
59-
}
60-
7 -> {
61-
Box(Modifier.fillMaxSize()) {
62-
GlowingRingLoader(Modifier.align(Alignment.Center))
63-
}
64-
}
65-
6 -> {
66-
Box(Modifier.fillMaxSize()) {
67-
YahooWeatherAndSun(Modifier.align(Alignment.Center))
68-
}
69-
}
70-
10 -> {
71-
Box(modifier = Modifier.fillMaxSize()) {
72-
IOSSleepSchedule()
73-
}
74-
}
75-
12 -> {
76-
TwitterSplashAnimation()
77-
}
78-
13 -> {
79-
AndroidMadSkills()
80-
}
81-
0 -> {
82-
ShootingStarsAnimation()
83-
}
84-
14 -> {
85-
NetflixIntroAnimation()
86-
}
87-
11 -> {
88-
Box(modifier = Modifier.fillMaxSize()) {
89-
Github404(Modifier)
90-
}
91-
}
92-
9 -> {
93-
Box(modifier = Modifier.fillMaxSize()) {
94-
ScalingRotatingLoader()
95-
}
96-
}
97-
8 -> {
98-
Box(Modifier.fillMaxSize()) {
99-
PlanetarySystem(Modifier.align(Alignment.Center))
100-
}
101-
}
102-
1 -> {
103-
Box(Modifier.fillMaxSize()) {
104-
LikeAnimation(Modifier.align(Alignment.Center))
105-
}
106-
}
107-
2 -> {
108-
Box(Modifier.fillMaxSize()) {
109-
ChatMessageReactions(Modifier.align(Alignment.Center))
110-
}
111-
}
112-
3 -> {
113-
Box(Modifier.fillMaxSize()) {
114-
MenuToClose(Modifier.align(Alignment.Center))
115-
}
116-
}
117-
5 -> {
118-
Box(Modifier.fillMaxSize()) {
119-
BellAnimation(Modifier.align(Alignment.Center))
120-
}
121-
}
122-
}
123-
}
124-
HorizontalPagerIndicator(
125-
pagerState = pagerState,
126-
modifier = Modifier
127-
.align(Alignment.BottomCenter)
128-
.padding(16.dp)
129-
)
130-
}
47+
AnimationsPager()
13148
}
13249
}
13350
}
13451
}
13552
}
13653
}
54+
55+
@OptIn(ExperimentalPagerApi::class)
56+
@Composable
57+
private fun AnimationsPager() {
58+
val pagerState = rememberPagerState()
59+
Box(
60+
modifier = Modifier
61+
.fillMaxSize()
62+
) {
63+
HorizontalPager(
64+
modifier = Modifier.fillMaxSize(),
65+
count = 15, state = pagerState,
66+
) { page ->
67+
// Our page content
68+
when (page) {
69+
4 -> {
70+
PullToRefreshOne()
71+
}
72+
7 -> {
73+
Box(Modifier.fillMaxSize()) {
74+
GlowingRingLoader(Modifier.align(Alignment.Center))
75+
}
76+
}
77+
0 -> {
78+
Box(Modifier.fillMaxSize()) {
79+
YahooWeatherAndSun(Modifier.align(Alignment.Center))
80+
}
81+
}
82+
10 -> {
83+
Box(modifier = Modifier.fillMaxSize()) {
84+
IOSSleepSchedule()
85+
}
86+
}
87+
12 -> {
88+
TwitterSplashAnimation()
89+
}
90+
13 -> {
91+
AndroidMadSkills()
92+
}
93+
14 -> {
94+
ShootingStarsAnimation()
95+
}
96+
6 -> {
97+
NetflixIntroAnimation()
98+
}
99+
11 -> {
100+
Box(modifier = Modifier.fillMaxSize()) {
101+
Github404(Modifier)
102+
}
103+
}
104+
9 -> {
105+
Box(modifier = Modifier.fillMaxSize()) {
106+
ScalingRotatingLoader()
107+
}
108+
}
109+
8 -> {
110+
Box(Modifier.fillMaxSize()) {
111+
PlanetarySystem(Modifier.align(Alignment.Center))
112+
}
113+
}
114+
1 -> {
115+
Box(Modifier.fillMaxSize()) {
116+
LikeAnimation(Modifier.align(Alignment.Center))
117+
}
118+
}
119+
2 -> {
120+
Box(Modifier.fillMaxSize()) {
121+
ChatMessageReactions(Modifier.align(Alignment.Center))
122+
}
123+
}
124+
3 -> {
125+
Box(Modifier.fillMaxSize()) {
126+
MenuToClose(Modifier.align(Alignment.Center))
127+
}
128+
}
129+
5 -> {
130+
Box(Modifier.fillMaxSize()) {
131+
BellAnimation(Modifier.align(Alignment.Center))
132+
}
133+
}
134+
}
135+
}
136+
HorizontalPagerIndicator(
137+
pagerState = pagerState,
138+
modifier = Modifier
139+
.align(Alignment.BottomCenter)
140+
.padding(16.dp)
141+
)
142+
}
143+
}
137144
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /