<lambda>null1package com.airbnb.lottie.sample.compose.examples 2 3 import androidx.compose.foundation.clickable 4 import androidx.compose.foundation.layout.Box 5 import androidx.compose.foundation.layout.Column 6 import androidx.compose.foundation.layout.fillMaxSize 7 import androidx.compose.foundation.layout.fillMaxWidth 8 import androidx.compose.foundation.layout.height 9 import androidx.compose.foundation.layout.padding 10 import androidx.compose.foundation.rememberScrollState 11 import androidx.compose.foundation.verticalScroll 12 import androidx.compose.material.Text 13 import androidx.compose.runtime.Composable 14 import androidx.compose.runtime.getValue 15 import androidx.compose.runtime.mutableStateOf 16 import androidx.compose.runtime.remember 17 import androidx.compose.runtime.setValue 18 import androidx.compose.ui.Alignment 19 import androidx.compose.ui.Modifier 20 import androidx.compose.ui.graphics.Color 21 import androidx.compose.ui.unit.dp 22 import com.airbnb.lottie.compose.LottieAnimation 23 import com.airbnb.lottie.compose.LottieCompositionSpec 24 import com.airbnb.lottie.compose.rememberLottieComposition 25 import com.airbnb.lottie.compose.rememberLottieRetrySignal 26 27 @Composable 28 fun NetworkExamplesPage() { 29 UsageExamplePageScaffold { 30 Column( 31 modifier = Modifier 32 .fillMaxWidth() 33 .verticalScroll(rememberScrollState()) 34 ) { 35 Box(modifier = Modifier.height(16.dp)) 36 ExampleCard("Example 1", "Basic URL") { 37 Example1() 38 } 39 ExampleCard("Example 2", "Fail with retries. Click to retry.") { 40 Example2() 41 } 42 } 43 } 44 } 45 46 @Composable Example1null47private fun Example1() { 48 val composition by rememberLottieComposition(LottieCompositionSpec.Url("https://raw.githubusercontent.com/airbnb/lottie-android/master/sample/src/main/res/raw/heart.json")) 49 LottieAnimation(composition) 50 } 51 52 @Composable Example2null53private fun Example2() { 54 val retrySignal = rememberLottieRetrySignal() 55 var failedCount by remember { mutableStateOf(0) } 56 val composition by rememberLottieComposition( 57 LottieCompositionSpec.Url("not a url"), 58 onRetry = { fc, _ -> 59 failedCount = fc 60 // Await the retry signal. 61 retrySignal.awaitRetry() 62 true 63 } 64 ) 65 Box( 66 modifier = Modifier 67 .fillMaxSize() 68 .clickable { retrySignal.retry() } 69 ) { 70 LottieAnimation(composition) 71 Text( 72 "Failed $failedCount times.\nAwaiting retry: ${retrySignal.isAwaitingRetry}", 73 color = Color.LightGray, 74 modifier = Modifier 75 .padding(8.dp) 76 .align(Alignment.BottomStart) 77 ) 78 } 79 }