I’m facing some issues trying to do this kind of f...
# compose
e
I’m facing some issues trying to do this kind of flip animation. I’m using
graphicsLayer
to flip the card component and it’s working. But the problem is with the content, I dont know how to sync the both sides with the flip. Any tips?
z
What do you mean sync both sides? Is there some issue in that gif? Looks fine to me
e
The gif is just a sample from internet… Inside the card component, I tried to put the content of both side controlled by a rotated variable:
Copy code
if (!rotated) 
CreditCardFront(...)
else
CreditCardBack(...)
but, when I change the
rotate
value, it draws the compose, and after, do the animations. I dont know how to sincronize the animation with the composable…
c
Can you post a gif of what your code snippet currently looks like?
e
c
That looks good 😄 What's the issue again? Is it that the numbers are flipped?
p
the card is switched immediately and then the animation happens
👆 1
each card should do its own rotation, not the parent of the two
you do half of the rotation in the visible one and set visibility to false once the half of the rotation is done and the other way around with the one that will appear
Copy code
Card(Modifier
.graphicsLayer(rotationY = rotation)
.visibility(rotationY > X) {
  CreditCardFront()
}

Card(Modifier
.graphicsLayer(rotationY = rotation)
.visibility(rotationY < X) {
  CreditCardBack()
}
you get the idea with this pseudocode
dont use
rotated
variable to render your UI, just to trigger the animation, and base the rest of the UI rendering only on
rotationY
varible
z
You could also only compose the side you're showing:
Copy code
Card(Modifier.graphicsLayer(rotationY = rotation)) {
  if (rotationY > X) {
    CreditCardFront()
  } else {
    CreditCardBack()
  }
}
5
p
yeah, that is better
e
it works…
Copy code
if (rotation < 90F) {
    CreditCardFront()
} else {
    CreditCardBack()
}
and then
Copy code
fun CreditCardBack() {
        Column(
            modifier = Modifier.graphicsLayer {
    rotationY = 180F
....
}
thanks a lot, I updated the gist
p
looks great!
z
one other tip, if you weren't already aware: you can change the
cameraDistance
to control kind of how intense that perspective effect is. Docs here.
👍🏽 1
👍 2