@@ -11,13 +11,16 @@ import androidx.compose.animation.core.spring
1111import androidx.compose.animation.core.tween
1212import androidx.compose.foundation.ExperimentalFoundationApi
1313import androidx.compose.foundation.Image
14+ import androidx.compose.foundation.background
15+ import androidx.compose.foundation.clickable
1416import androidx.compose.foundation.gestures.AnchoredDraggableState
1517import androidx.compose.foundation.gestures.DraggableAnchors
1618import androidx.compose.foundation.gestures.Orientation
1719import androidx.compose.foundation.gestures.anchoredDraggable
1820import androidx.compose.foundation.gestures.animateTo
1921import androidx.compose.foundation.gestures.detectTransformGestures
2022import androidx.compose.foundation.gestures.detectVerticalDragGestures
23+ import androidx.compose.foundation.interaction.MutableInteractionSource
2124import androidx.compose.foundation.layout.Arrangement
2225import androidx.compose.foundation.layout.Box
2326import androidx.compose.foundation.layout.Column
@@ -27,6 +30,8 @@ import androidx.compose.foundation.layout.Spacer
2730import androidx.compose.foundation.layout.fillMaxHeight
2831import androidx.compose.foundation.layout.fillMaxSize
2932import androidx.compose.foundation.layout.fillMaxWidth
33+ import androidx.compose.foundation.layout.height
34+ import androidx.compose.foundation.layout.navigationBarsPadding
3035import androidx.compose.foundation.layout.offset
3136import androidx.compose.foundation.layout.padding
3237import androidx.compose.foundation.layout.size
@@ -38,12 +43,14 @@ import androidx.compose.material3.NavigationBar
3843import androidx.compose.material3.NavigationBarItem
3944import androidx.compose.material3.NavigationBarItemDefaults
4045import androidx.compose.material3.Scaffold
46+ import androidx.compose.material3.Slider
4147import androidx.compose.material3.Text
4248import androidx.compose.runtime.Composable
4349import androidx.compose.runtime.LaunchedEffect
4450import androidx.compose.runtime.State
4551import androidx.compose.runtime.collectAsState
4652import androidx.compose.runtime.getValue
53+ import androidx.compose.runtime.mutableFloatStateOf
4754import androidx.compose.runtime.mutableStateOf
4855import androidx.compose.runtime.remember
4956import androidx.compose.runtime.rememberCoroutineScope
@@ -75,6 +82,11 @@ import androidx.navigation.compose.composable
7582import androidx.navigation.compose.currentBackStackEntryAsState
7683import androidx.navigation.compose.rememberNavController
7784import androidx.navigation.navigation
85+ import com.airbnb.lottie.compose.LottieAnimation
86+ import com.airbnb.lottie.compose.LottieCompositionSpec
87+ import com.airbnb.lottie.compose.LottieConstants
88+ import com.airbnb.lottie.compose.rememberLottieAnimatable
89+ import com.airbnb.lottie.compose.rememberLottieComposition
7890import com.facebook.Profile
7991import com.google.firebase.auth.ktx.auth
8092import com.google.firebase.ktx.Firebase
@@ -106,12 +118,15 @@ class MainActivity : ComponentActivity() {
106118 super .onCreate(savedInstanceState)
107119 WindowCompat .setDecorFitsSystemWindows(window, false )
108120
109- val testMode = false
121+ val testMode = true
110122
111123 if (testMode) {
112124 setContent {
113- Box {
114- FeedScreen (posts = SampleData ().posts)
125+ Box (
126+ Modifier .fillMaxSize(),
127+ contentAlignment = Alignment .Center
128+ ) {
129+ LottieStyles ()
115130 }
116131 }
117132 } else {
@@ -164,6 +179,186 @@ class MainActivity : ComponentActivity() {
164179 }
165180 }
166181
182+ @Composable
183+ private fun LottieStyles () {
184+ val url =
185+ " https://lottie.host/a2a247fa-25e6-4884-b30c-47af6bb0ce31/3Bz9KEEqBj.json"
186+
187+ val sampleTest = 3
188+ when (sampleTest) {
189+ 1 -> {
190+ val composition by rememberLottieComposition(
191+ spec = LottieCompositionSpec .Url (
192+ url
193+ )
194+ )
195+
196+ LottieAnimation (
197+ composition = composition,
198+ iterations = LottieConstants .IterateForever
199+ )
200+ }
201+
202+ 2 -> {
203+ val anim = rememberLottieAnimatable()
204+ val composition by rememberLottieComposition(
205+ LottieCompositionSpec .Url (url)
206+ )
207+ var sliderGestureProgress: Float? by remember { mutableStateOf(null ) }
208+ LaunchedEffect (composition, sliderGestureProgress) {
209+ when (val p = sliderGestureProgress) {
210+ null -> anim.animate(
211+ composition,
212+ iterations = 0 ,
213+ initialProgress = anim.progress,
214+ continueFromPreviousAnimate = false ,
215+ )
216+
217+ else -> anim.snapTo(progress = p)
218+ }
219+ }
220+ Box (Modifier .padding(bottom = 32 .dp)) {
221+ LottieAnimation (anim.composition, { anim.progress })
222+ Slider (
223+ value = sliderGestureProgress ? : anim.progress,
224+ onValueChange = { sliderGestureProgress = it },
225+ onValueChangeFinished = { sliderGestureProgress = null },
226+ modifier = Modifier
227+ .align(Alignment .BottomCenter )
228+ .padding(bottom = 8 .dp)
229+ )
230+ }
231+ }
232+
233+ 3 -> {
234+ var previsousProgress by remember { mutableFloatStateOf(0f ) }
235+ var speed by remember { mutableFloatStateOf(0f ) }
236+ val composition by rememberLottieComposition(
237+ LottieCompositionSpec .RawRes (
238+ R .raw.logo_lines_animated
239+ )
240+ )
241+ val animatable = rememberLottieAnimatable()
242+
243+ LaunchedEffect (speed) {
244+ animatable.animate(
245+ composition,
246+ iteration = LottieConstants .IterateForever ,
247+ speed = speed,
248+ initialProgress = previsousProgress,
249+ )
250+ }
251+ val interactionSource = remember { MutableInteractionSource () }
252+
253+ LottieAnimation (
254+ composition = composition,
255+ progress = { animatable.progress },
256+ modifier = Modifier
257+ .clickable(
258+ interactionSource = interactionSource,
259+ indication = null
260+ ) {
261+ speed = if (speed == 0f ) 1f else 0f
262+ previsousProgress = animatable.progress
263+ }
264+ )
265+ }
266+
267+ 4 -> {
268+ var previsousProgress by remember { mutableStateOf(0f ) }
269+ var velocity by remember { mutableStateOf(0f ) }
270+ var shouldPlay by remember { mutableStateOf(true ) }
271+ val composition by rememberLottieComposition(
272+ LottieCompositionSpec .Url (
273+ url
274+ )
275+ )
276+ val animatable = rememberLottieAnimatable()
277+
278+ // LaunchedEffect(composition, shouldPlay) {
279+ // if (composition == null || !shouldPlay) return@LaunchedEffect
280+ // animatable.animate(
281+ // composition,
282+ // iteration = LottieConstants.IterateForever,
283+ // )
284+ // }
285+
286+ LaunchedEffect (shouldPlay) {
287+ animatable.animate(
288+ composition,
289+ iteration = LottieConstants .IterateForever ,
290+ speed = velocity,
291+ initialProgress = previsousProgress,
292+ )
293+ }
294+ val interactionSource = remember { MutableInteractionSource () }
295+
296+
297+ LottieAnimation (
298+ composition = composition,
299+ progress = { animatable.progress },
300+ modifier = Modifier
301+ .clickable(
302+ interactionSource = interactionSource,
303+ indication = null
304+ ) {
305+ shouldPlay = ! shouldPlay
306+ velocity = if (velocity == 0f ) 1f else 0f
307+ previsousProgress = animatable.progress
308+ }
309+ )
310+
311+ Text (
312+ text = " Progresso: ${animatable.progress} " ,
313+ Modifier .offset(y = (- 300 ).dp)
314+ )
315+ }
316+
317+ 5 -> {
318+ val anim = rememberLottieAnimatable()
319+ val composition by rememberLottieComposition(
320+ LottieCompositionSpec .Url (
321+ url
322+ )
323+ )
324+ var speed by remember { mutableStateOf(1f ) }
325+ LaunchedEffect (composition, speed) {
326+ anim.animate(
327+ composition,
328+ iterations = LottieConstants .IterateForever ,
329+ speed = speed,
330+ initialProgress = anim.progress,
331+ )
332+ }
333+ Column (
334+ Modifier .navigationBarsPadding()
335+ ) {
336+ Box {
337+ LottieAnimation (composition, { anim.progress })
338+ Slider (
339+ value = speed,
340+ onValueChange = { speed = it },
341+ valueRange = - 3f .. 3f ,
342+ modifier = Modifier
343+ .align(Alignment .BottomCenter )
344+ .padding(bottom = 8 .dp)
345+ )
346+ Box (
347+ modifier = Modifier
348+ .align(Alignment .BottomCenter )
349+ .padding(bottom = 24 .dp)
350+ .size(width = 1 .dp, height = 16 .dp)
351+ .background(Color .Black )
352+ )
353+ }
354+ Spacer (modifier = Modifier .height(32 .dp))
355+ }
356+
357+
358+ }
359+ }
360+ }
361+
167362 @Composable
168363 fun ThreadsApp (
169364 content : @Composable (PaddingValues ) -> Unit ,
0 commit comments