Is there anything similar to animateLayoutChanges ...
# compose
y
Is there anything similar to animateLayoutChanges on Compose? I am trying to toggle the visibility of a layout using AnimatedVisibility but the final animation does not run as smoothly as animateLayoutChanges would but just toggling the visibility of a View. Also my Spacer fully disappears when its placed in an AnimatedVisibility which I am not sure why
c
From my experience AnimatedVisibility works much better than animateLayoutChanges. Post your code + a video and the Compose animation hero we don't deserve (Doris Liu) might just grace us with her presence.
y
If I tap too fast it will just change its visibility without animation
c
Can you post the actual code so I can run locally and try to repro?
y
ok w8
👍 1
I wonder if I can use a float variable to manually animate it - so its not true or false, its always a number from 0 to 1. it wont snap that way I suppose.
i
AnimatedVisibility
is already keeping track of the float of the current animated size and moving it in the direction of your `visible`: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]kotlin/androidx/compose/animation/AnimatedVisibility.kt;l=283
👆 1
r
Also my Spacer fully disappears when its placed in an AnimatedVisibility which I am not sure why
I ran into this too, so it's not just you.
y
@Ian Lake Then why my animation does not work properly? If its on 50% and the user clicks again, I want the animation to smoothly change its direction but it just snaps to the final position. You can try it for yourself using the repo.
d
Which version of compose do you see this on? The animation should never snap to the final position in
AnimatedVisibility
- it is designed to always animate from the value at the point of interruption to the new target. (This is also the default behavior for all animations in compose.)
👍 1
Also my Spacer fully disappears when its placed in an AnimatedVisibility which I am not sure why
AnimatedVisibility
uses a custom layout that stacks all the children like a Box/FrameLayout. That is why Spacer doesn't offset the other content in AnimatedVisibility. You could try creating a Row/Column in AnimatedVisibility for the Spacer and other content. 🙂
👍 2