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

Ilias Zosimadis

02/17/2021, 1:55 PM
What is the best way to animate the shape of a
Surface
? Should I use a custom shape with
createOutline
or create a custom surface composable with
Canvas
?
a

Ali Albaali

02/17/2021, 2:14 PM
What are you trying to animate? If it's something trivial such as corners width, surface size or color then that's can be done easily with animateFooAsState API.
i

Ilias Zosimadis

02/17/2021, 2:21 PM
i

Ilias Zosimadis

02/17/2021, 2:36 PM
So you are creating a new shape for each fraction of your animation. That's one solution but you can also do the same thing if you create a custom Surface and use your fraction there. What do you think is the best solution (or the recommended way) between these two?
a

Andrey Kulikov

02/17/2021, 3:14 PM
I think creating a shape for each fraction is fine. note that Shape implementations should be immutable, so you have to recreate a shape object if you changed something which describes the shape
👍 1
a

Albert Chang

02/18/2021, 9:26 AM
If you know the specific type of the shape then of course you can draw it manually but it is impossible at least in my use case as you don't know how the shape is drawn (i.e. how the outline is created). Even if you only support a subset of the shapes, you need a lot of boilerplate code.
👍 1
4 Views