Skip to content

Commit

Permalink
Added Successful button to complete animation as Success.
Browse files Browse the repository at this point in the history
  • Loading branch information
canerkaseler committed Jun 24, 2023
1 parent 33acdc8 commit 25832d2
Showing 1 changed file with 29 additions and 4 deletions.
Expand Up @@ -3,12 +3,19 @@ package com.canerkaseler.composelottie
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieClipSpec
import com.airbnb.lottie.compose.LottieCompositionSpec
Expand All @@ -17,25 +24,43 @@ import com.airbnb.lottie.compose.rememberLottieComposition

@Composable
fun ComposeLottieScreen() {

var isSuccess by remember { mutableStateOf(false) }

Box(modifier = Modifier
.fillMaxSize()
.background(color = Color.White)
){
ComposeLottieAnimation(modifier = Modifier.align(alignment = Alignment.Center))
ComposeLottieAnimation(
modifier = Modifier.align(alignment = Alignment.Center),
isCompleted = isSuccess
)

Button(
modifier = Modifier.align(alignment = Alignment.BottomCenter).padding(bottom = 45.dp),
onClick = { isSuccess = true }
) {
Text(
text = "Successful"
)
}
}
}

@Composable
fun ComposeLottieAnimation(modifier: Modifier) {
fun ComposeLottieAnimation(modifier: Modifier, isCompleted: Boolean) {

val clipSpecs = LottieClipSpec.Progress(0.2f, 0.5f)
val clipSpecs = LottieClipSpec.Progress(
min = 0.0f,
max = if (isCompleted) 0.44f else 0.282f
)

val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.anim_loading_success_failed))

LottieAnimation(
modifier = modifier,
composition = composition,
iterations = LottieConstants.IterateForever,
iterations = if (isCompleted) 1 else LottieConstants.IterateForever,
clipSpec = clipSpecs,
)
}
Expand Down

0 comments on commit 25832d2

Please sign in to comment.