https://kotlinlang.org logo
#compose
Title
# compose
a

Alexander Sitnikov

10/22/2020, 5:53 PM
I want to create a card flip animation (

like this

), and the only way I found is using
Modifier.drawLayer(rotationY = someValue)
, but this animation looks too distorted (

like this

). View has
setCameraDistance()
method, and RenderNode has this method too, but Compose doesn't use any of them. It seems to me that
rotationY
parameter is kinda useless without camera distance. Is there any way to create this card flip animation other than
drawLayer
? Or maybe there's plans to include support for camera distance in future versions of Compose?
l

Leland Richardson [G]

10/22/2020, 5:54 PM
cc @Nader Jawad
r

romainguy

10/22/2020, 5:56 PM
That’s because Skia doesn’t do perspective correc transformations
Camera distance would help but only to a certain point
Still, seems worth adding
(or picking a better default)
h

Halil Ozercan

10/22/2020, 5:57 PM
@romainguy
Camera distance would help but only to a certain point
I was also going to say the same thing. Maybe scaling the view while also doing the animation help but not sure about that either
r

romainguy

10/22/2020, 5:57 PM
No, the problem is more fundamental
z

Zach Klippenstein (he/him) [MOD]

10/22/2020, 5:58 PM
h

Halil Ozercan

10/22/2020, 5:58 PM
yes, now thinking about scaling, the far end would look very weird
z

Zach Klippenstein (he/him) [MOD]

10/22/2020, 5:58 PM
looks like this:

https://github.com/zach-klippenstein/compose-backstack/raw/main/.images/inspector.gif

r

romainguy

10/22/2020, 5:59 PM
The text looks very very wrong in your example 😛
These “3D” rotations are just shears/skews, which is why it looks bad on text or images
a

Alexander Sitnikov

10/22/2020, 6:28 PM
should I file an issue then?
r

romainguy

10/22/2020, 7:47 PM
Yes please
s

Sergey Y.

10/22/2020, 8:02 PM
@Alexander Sitnikov But keep in mind that changes to the Skia runtime can only ship with a newer version of Android. Compose does not ship with its own version of Skia. 🙄
a

Alexander Sitnikov

10/22/2020, 8:43 PM
r

romainguy

10/22/2020, 9:27 PM
We’re not talking about introducing true 3D transforms here, just the camera distance 🙂
👍 1
This doesn’t require touching Skia
👍 2
n

Nader Jawad

11/04/2020, 3:11 AM
camera distance has been added to the layer APIs in compose and should be available in a future release of compose
🎉 5
r

romainguy

11/04/2020, 4:48 AM
Awesome, thanks Nader!
👍 1
34 Views