How can I achieve this Button Animation in Jetpack Compose?

Yannick

I want to build this awesome button animation pressed from the AirBnB App with Jetpack Compose 1

Unfortunately, the Animation/Transition API was changed recently and there's almost no documentation for it. Can someone help me get the right approach to implement this button press animation?

Edit Based on @Amirhosein answer I have developed a button that looks almost exactly like the Airbnb example

Code:

@Composable
fun AnimatedButton() {
    val boxHeight = animatedFloat(initVal = 50f)
    val relBoxWidth = animatedFloat(initVal = 1.0f)
    val fontSize = animatedFloat(initVal = 16f)

    fun animateDimensions() {
        boxHeight.animateTo(45f)
        relBoxWidth.animateTo(0.95f)
       // fontSize.animateTo(14f)
    }

    fun reverseAnimation() {
        boxHeight.animateTo(50f)
        relBoxWidth.animateTo(1.0f)
        //fontSize.animateTo(16f)
    }

        Box(
        modifier = Modifier
            .height(boxHeight.value.dp)
            .fillMaxWidth(fraction = relBoxWidth.value)

            .clip(RoundedCornerShape(8.dp))
            .background(Color.Black)
            .clickable { }
            .pressIndicatorGestureFilter(
                onStart = {
                    animateDimensions()
                },
                onStop = {
                    reverseAnimation()
                },
                onCancel = {
                    reverseAnimation()
                }
            ),
        contentAlignment = Alignment.Center
    ) {
        Text(text = "Explore Airbnb", fontSize = fontSize.value.sp, color = Color.White)
    }
}

Video:

2

Unfortunately, I cannot figure out how to animate the text correctly as It looks very bad currently

Code Poet

Are you looking for something like this?

@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)
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I achieve this Button Animation in Jetpack Compose?

From Java

How can I get onTouchEvent in Jetpack Compose?

From Dev

How can i achieve this mouse movement triggered animation?

From Dev

Can I write Jetpack Compose components in Java?

From Dev

How can I achieve a 30 button grid using autolayout storyboards?

From Dev

Jetpack Compose list diffs animation

From Dev

How can achieve this custom view wave animation?

From Java

How can I achieve a CSS text loading animation over multiple lines?

From Dev

In mvc how can i achieve loading animation while page is transforming from one to another

From Dev

How can I achieve this view?

From Dev

How can I achieve setOnLongClickListener?

From Dev

How can I achieve this view?

From Dev

How to achieve Android Button Animation with text-blurred and shadow

From Dev

How can I use a single button click to achieve multiple actions in android eclipse?

From Dev

How can I use a single button click to achieve multiple actions in android eclipse?

From Dev

How do I achieve this animation using javascript/jquery?

From Dev

Button Long Press Listener in Android jetpack compose

From Dev

How to handle navigation in Jetpack Compose?

From Dev

RxJS and AngularJS HTTP - how can I achieve this?

From Dev

How can I achieve password regex?

From Dev

How can I achieve this Positioning with CSS?

From Dev

How can I achieve this ribbon effect with CSS?

From Dev

How can i achieve CoverFlow view

From Dev

Rails: How can I achieve this relationship model?

From Dev

How can I achieve the desired floats in Bootstrap?

From Dev

How can I achieve luminescent shadows?

From Dev

Android - How can I achieve this type of toolbar?

From Dev

How can I achieve this tab style in android?

From Dev

How can i achieve this in LINQ-Queries?

Related Related

  1. 1

    How can I achieve this Button Animation in Jetpack Compose?

  2. 2

    How can I get onTouchEvent in Jetpack Compose?

  3. 3

    How can i achieve this mouse movement triggered animation?

  4. 4

    Can I write Jetpack Compose components in Java?

  5. 5

    How can I achieve a 30 button grid using autolayout storyboards?

  6. 6

    Jetpack Compose list diffs animation

  7. 7

    How can achieve this custom view wave animation?

  8. 8

    How can I achieve a CSS text loading animation over multiple lines?

  9. 9

    In mvc how can i achieve loading animation while page is transforming from one to another

  10. 10

    How can I achieve this view?

  11. 11

    How can I achieve setOnLongClickListener?

  12. 12

    How can I achieve this view?

  13. 13

    How to achieve Android Button Animation with text-blurred and shadow

  14. 14

    How can I use a single button click to achieve multiple actions in android eclipse?

  15. 15

    How can I use a single button click to achieve multiple actions in android eclipse?

  16. 16

    How do I achieve this animation using javascript/jquery?

  17. 17

    Button Long Press Listener in Android jetpack compose

  18. 18

    How to handle navigation in Jetpack Compose?

  19. 19

    RxJS and AngularJS HTTP - how can I achieve this?

  20. 20

    How can I achieve password regex?

  21. 21

    How can I achieve this Positioning with CSS?

  22. 22

    How can I achieve this ribbon effect with CSS?

  23. 23

    How can i achieve CoverFlow view

  24. 24

    Rails: How can I achieve this relationship model?

  25. 25

    How can I achieve the desired floats in Bootstrap?

  26. 26

    How can I achieve luminescent shadows?

  27. 27

    Android - How can I achieve this type of toolbar?

  28. 28

    How can I achieve this tab style in android?

  29. 29

    How can i achieve this in LINQ-Queries?

HotTag

Archive