0

Here is the code how I implement my button. Is there any way to lottie animation took place without increase size and without apply fix height of button.

Button(modifier = Modifier
        .fillMaxWidth()
        .padding(horizontal = 10.dp),
        enabled = enabled,
        onClick = {
            onClick()
        }) {
        if (isLoading) {
            LottieAnimation(
                composition = composition,
                iterations = Int.MAX_VALUE,
                alignment = Alignment.Center,
                dynamicProperties = dynamicProperties,
            )
        } else {
            Text(
                text = text,
            )
        }
    }

1 Answers1

0
@Composable
fun AnimatedButton() {
    val selected = remember { mutableStateOf(false) }
    val scale = animateFloatAsState(if (selected.value) 2f else 1f)

    Column(
        Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Button(
            onClick = {  },
            modifier = Modifier
                .scale(scale.value)
                .height(40.dp)
                .width(200.dp)
                .pointerInteropFilter {
                    when (it.action) {
                        MotionEvent.ACTION_DOWN -> {
                            selected.value = true }

                        MotionEvent.ACTION_UP  -> {
                           selected.value = false }
                    }
                    true
                }
        ) {
            Text(text = "Explore Airbnb", fontSize = 15.sp, color = Color.White)
        }
    }
}