Skip to content

Commit 7239eaa

Browse files
committed
feat: Adicionado logo animado como ação de carregamento
Logo criado em .mp4 e convertido para formato da API Lottie através do site oficial Animação está em FeedScreen como recurso visual para ação de carregamento
1 parent 0fdecdb commit 7239eaa

File tree

2 files changed

+120
-6
lines changed

2 files changed

+120
-6
lines changed

app/src/main/java/com/paradoxo/threadscompose/MainActivity.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class MainActivity : ComponentActivity() {
118118
super.onCreate(savedInstanceState)
119119
WindowCompat.setDecorFitsSystemWindows(window, false)
120120

121-
val testMode = true
121+
val testMode = false
122122

123123
if (testMode) {
124124
setContent {
@@ -231,21 +231,24 @@ class MainActivity : ComponentActivity() {
231231
}
232232

233233
3 -> {
234-
var previsousProgress by remember { mutableFloatStateOf(0f) }
235-
var speed by remember { mutableFloatStateOf(0f) }
234+
var previousProgress by remember { mutableFloatStateOf(0f) }
235+
var speed by remember { mutableFloatStateOf(1f) }
236236
val composition by rememberLottieComposition(
237237
LottieCompositionSpec.RawRes(
238238
R.raw.logo_lines_animated
239239
)
240240
)
241241
val animatable = rememberLottieAnimatable()
242242

243+
val context = LocalContext.current
244+
context.showMessage(animatable.isPlaying.toString())
245+
243246
LaunchedEffect(speed) {
244247
animatable.animate(
245248
composition,
246249
iteration = LottieConstants.IterateForever,
247250
speed = speed,
248-
initialProgress = previsousProgress,
251+
initialProgress = previousProgress,
249252
)
250253
}
251254
val interactionSource = remember { MutableInteractionSource() }
@@ -259,7 +262,7 @@ class MainActivity : ComponentActivity() {
259262
indication = null
260263
) {
261264
speed = if (speed == 0f) 1f else 0f
262-
previsousProgress = animatable.progress
265+
previousProgress = animatable.progress
263266
}
264267
)
265268
}

app/src/main/java/com/paradoxo/threadscompose/ui/FeedScreen.kt

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import androidx.compose.animation.core.Animatable
44
import androidx.compose.animation.core.Spring
55
import androidx.compose.animation.core.spring
66
import androidx.compose.foundation.Image
7+
import androidx.compose.foundation.clickable
78
import androidx.compose.foundation.gestures.detectVerticalDragGestures
9+
import androidx.compose.foundation.interaction.MutableInteractionSource
810
import androidx.compose.foundation.layout.Arrangement
911
import androidx.compose.foundation.layout.Box
1012
import androidx.compose.foundation.layout.Row
@@ -17,6 +19,9 @@ import androidx.compose.foundation.layout.systemBarsPadding
1719
import androidx.compose.foundation.lazy.LazyColumn
1820
import androidx.compose.foundation.lazy.items
1921
import androidx.compose.runtime.Composable
22+
import androidx.compose.runtime.LaunchedEffect
23+
import androidx.compose.runtime.getValue
24+
import androidx.compose.runtime.mutableFloatStateOf
2025
import androidx.compose.runtime.mutableStateOf
2126
import androidx.compose.runtime.remember
2227
import androidx.compose.runtime.rememberCoroutineScope
@@ -28,6 +33,11 @@ import androidx.compose.ui.input.pointer.pointerInput
2833
import androidx.compose.ui.res.painterResource
2934
import androidx.compose.ui.tooling.preview.Preview
3035
import androidx.compose.ui.unit.dp
36+
import com.airbnb.lottie.compose.LottieAnimation
37+
import com.airbnb.lottie.compose.LottieCompositionSpec
38+
import com.airbnb.lottie.compose.LottieConstants
39+
import com.airbnb.lottie.compose.rememberLottieAnimatable
40+
import com.airbnb.lottie.compose.rememberLottieComposition
3141
import com.paradoxo.threadscompose.R
3242
import com.paradoxo.threadscompose.model.Post
3343
import kotlinx.coroutines.launch
@@ -45,7 +55,7 @@ fun FeedScreen(
4555
.systemBarsPadding()
4656
) {
4757
item {
48-
ExpandableAppLogo()
58+
ExpandableAppLogoLottie()
4959
}
5060

5161
items(
@@ -70,6 +80,107 @@ fun FeedScreen(
7080
}
7181
}
7282

83+
@Composable
84+
private fun ExpandableAppLogoLottie() {
85+
val maxHeightImage = 200.dp
86+
val defaultSizeImage = 72.dp
87+
val coroutineScope = rememberCoroutineScope()
88+
val animatedImageSize = remember { Animatable(defaultSizeImage.value) }
89+
90+
91+
val lottiePreviousProgress by remember { mutableFloatStateOf(0f) }
92+
val lottieSpeed by remember { mutableFloatStateOf(1f) }
93+
val lottieComposition by rememberLottieComposition(
94+
LottieCompositionSpec.RawRes(
95+
R.raw.logo_lines_animated
96+
)
97+
)
98+
val lottieAnimatable = rememberLottieAnimatable()
99+
100+
LaunchedEffect(lottieSpeed) {
101+
lottieAnimatable.animate(
102+
lottieComposition,
103+
iteration = LottieConstants.IterateForever,
104+
speed = lottieSpeed,
105+
)
106+
}
107+
108+
Box(
109+
modifier = Modifier
110+
.pointerInput(Unit) {
111+
detectVerticalDragGestures(
112+
onVerticalDrag = { change, offset ->
113+
coroutineScope.launch {
114+
val newSize =
115+
(animatedImageSize.value + offset / 8).coerceAtLeast(
116+
defaultSizeImage.value
117+
)
118+
if (newSize < maxHeightImage.value) {
119+
animatedImageSize.snapTo(newSize)
120+
}
121+
change.consume()
122+
}
123+
},
124+
onDragEnd = {
125+
coroutineScope.launch {
126+
animatedImageSize.animateTo(
127+
defaultSizeImage.value,
128+
animationSpec = spring(
129+
dampingRatio = Spring.DampingRatioLowBouncy,
130+
stiffness = Spring.StiffnessLow
131+
)
132+
)
133+
}
134+
coroutineScope.launch {
135+
lottieAnimatable.animate(
136+
lottieComposition,
137+
iteration = 1,
138+
speed = lottieSpeed,
139+
reverseOnRepeat = true,
140+
initialProgress = lottiePreviousProgress,
141+
)
142+
}
143+
},
144+
onDragStart = {
145+
coroutineScope.launch {
146+
lottieAnimatable.animate(
147+
lottieComposition,
148+
iteration = LottieConstants.IterateForever,
149+
speed = lottieSpeed,
150+
initialProgress = lottiePreviousProgress,
151+
)
152+
}
153+
}
154+
)
155+
}
156+
) {
157+
// To remove click animation of clickable modifier
158+
val interactionSource = remember { MutableInteractionSource() }
159+
160+
Row(
161+
modifier = Modifier
162+
.fillMaxWidth()
163+
.clickable(
164+
interactionSource = interactionSource,
165+
indication = null
166+
) {
167+
// lottieSpeed = if (lottieSpeed == 0f) 1f else 0f
168+
// lottiePreviousProgress = lottieAnimatable.progress
169+
},
170+
horizontalArrangement = Arrangement.Center,
171+
) {
172+
173+
LottieAnimation(
174+
composition = lottieComposition,
175+
progress = { lottieAnimatable.progress },
176+
modifier = Modifier
177+
.size(animatedImageSize.value.dp)
178+
)
179+
180+
}
181+
}
182+
}
183+
73184
@Composable
74185
private fun ExpandableAppLogo() {
75186
val maxHeightImage = 200.dp

0 commit comments

Comments
 (0)