2

I'm trying to recreate the animation for the expanded Speed Dial shown on the Material Design website but I'm struggling to achieve the exact same result in Compose. For now I tried to play with the AnimatedVisibility of the ColumnScope but I don't thin it's possible to replicate the same behavior.

Any suggestion on how to achieve this?

enter image description here

2 Answers 2

2

I found the expected output by using Floating Action Button Speed Dial library.

The library is available on Jcenter so no additonal repository is required.

Check whether you get the desired result https://github.com/leinardi/FloatingActionButtonSpeedDial.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm the developer of that library :-) I'm trying to create a Compose version of it but I don't know how to do that animation in Compose.
Well, I ended up implementing it into my library so, I guess, yours can now be considered the right answer :-) Source code available here
0

It can definitely be achieved, that's for sure. One method that I can think of currently is something like this:

Create a single Composable that accepts a state (shown/hidden) and any other parameters you require. Inside that, create a state-holder for the visibility of each dial item, and trigger the animation on them at certain millis apart from each other.

Something like this

@Composable
fun SpeedDial(expanded: Boolean){
 LaunchedEffect(expanded){
  handleAnimation()
 }

 val visibilityList = remember { mutableStateListOf<Boolean>(/* List Of Booleans */) }
 AnimatedVisibility(visible == visibilityList(0)){
  Item1() // Visible only if the first item in list is visible
 } 

 // Copy-paste for other items

 suspend fun handleAnimation() {
  visibilityList.forEachIndexed { index, visibility ->
    visibilityList.set(index, expanded)
    delay(150) // Alter per-requirement
  }
 }

}

This should achieve the effect without lag. Try it out.

3 Comments

Initialize the list with as many Booleans as there are items in your speed dial. You should initialize its every index with value of expanded received currently. It will not be re-initialized with that because of remember.
Hey thank you for the suggestion but I found out that some animationSpec of AnimatedVisibility, like tween can take a delayMillis and that can be used to delay the animations without the need to do it directly with coroutine.
Well as long as the problem was resolved, cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.