@@ -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
@@ -110,8 +122,11 @@ class MainActivity : ComponentActivity() {
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,189 @@ 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 previousProgress by remember { mutableFloatStateOf(0f ) }
235+ var speed by remember { mutableFloatStateOf(1f ) }
236+ val composition by rememberLottieComposition(
237+ LottieCompositionSpec .RawRes (
238+ R .raw.logo_lines_animated
239+ )
240+ )
241+ val animatable = rememberLottieAnimatable()
242+
243+ val context = LocalContext .current
244+ context.showMessage(animatable.isPlaying.toString())
245+
246+ LaunchedEffect (speed) {
247+ animatable.animate(
248+ composition,
249+ iteration = LottieConstants .IterateForever ,
250+ speed = speed,
251+ initialProgress = previousProgress,
252+ )
253+ }
254+ val interactionSource = remember { MutableInteractionSource () }
255+
256+ LottieAnimation (
257+ composition = composition,
258+ progress = { animatable.progress },
259+ modifier = Modifier
260+ .clickable(
261+ interactionSource = interactionSource,
262+ indication = null
263+ ) {
264+ speed = if (speed == 0f ) 1f else 0f
265+ previousProgress = animatable.progress
266+ }
267+ )
268+ }
269+
270+ 4 -> {
271+ var previsousProgress by remember { mutableStateOf(0f ) }
272+ var velocity by remember { mutableStateOf(0f ) }
273+ var shouldPlay by remember { mutableStateOf(true ) }
274+ val composition by rememberLottieComposition(
275+ LottieCompositionSpec .Url (
276+ url
277+ )
278+ )
279+ val animatable = rememberLottieAnimatable()
280+
281+ // LaunchedEffect(composition, shouldPlay) {
282+ // if (composition == null || !shouldPlay) return@LaunchedEffect
283+ // animatable.animate(
284+ // composition,
285+ // iteration = LottieConstants.IterateForever,
286+ // )
287+ // }
288+
289+ LaunchedEffect (shouldPlay) {
290+ animatable.animate(
291+ composition,
292+ iteration = LottieConstants .IterateForever ,
293+ speed = velocity,
294+ initialProgress = previsousProgress,
295+ )
296+ }
297+ val interactionSource = remember { MutableInteractionSource () }
298+
299+
300+ LottieAnimation (
301+ composition = composition,
302+ progress = { animatable.progress },
303+ modifier = Modifier
304+ .clickable(
305+ interactionSource = interactionSource,
306+ indication = null
307+ ) {
308+ shouldPlay = ! shouldPlay
309+ velocity = if (velocity == 0f ) 1f else 0f
310+ previsousProgress = animatable.progress
311+ }
312+ )
313+
314+ Text (
315+ text = " Progresso: ${animatable.progress} " ,
316+ Modifier .offset(y = (- 300 ).dp)
317+ )
318+ }
319+
320+ 5 -> {
321+ val anim = rememberLottieAnimatable()
322+ val composition by rememberLottieComposition(
323+ LottieCompositionSpec .Url (
324+ url
325+ )
326+ )
327+ var speed by remember { mutableStateOf(1f ) }
328+ LaunchedEffect (composition, speed) {
329+ anim.animate(
330+ composition,
331+ iterations = LottieConstants .IterateForever ,
332+ speed = speed,
333+ initialProgress = anim.progress,
334+ )
335+ }
336+ Column (
337+ Modifier .navigationBarsPadding()
338+ ) {
339+ Box {
340+ LottieAnimation (composition, { anim.progress })
341+ Slider (
342+ value = speed,
343+ onValueChange = { speed = it },
344+ valueRange = - 3f .. 3f ,
345+ modifier = Modifier
346+ .align(Alignment .BottomCenter )
347+ .padding(bottom = 8 .dp)
348+ )
349+ Box (
350+ modifier = Modifier
351+ .align(Alignment .BottomCenter )
352+ .padding(bottom = 24 .dp)
353+ .size(width = 1 .dp, height = 16 .dp)
354+ .background(Color .Black )
355+ )
356+ }
357+ Spacer (modifier = Modifier .height(32 .dp))
358+ }
359+
360+
361+ }
362+ }
363+ }
364+
167365 @Composable
168366 fun ThreadsApp (
169367 content : @Composable (PaddingValues ) -> Unit ,
0 commit comments