is there any way to animate between two textstyles...
# compose
v
is there any way to animate between two textstyles?
k
How would you expect this to work across completely different font families, multiline texts, etc?
v
I would like to do something like scale down/up based on a state. I m trying to use
updateTransition
. Probably I need to rewrite the
animateDp
and have something similar but for sp, right? Additinionally, i think it woul be nice to have something similar but for padding values (
animatePaddingValues
). Now, I call 4 times the
animateDp
to update the padding values.
k
There's way more to
TextStyle
than just font size
v
of course! But most of these values could be animated separately. So I would expect to have a transition from these values to the values that are declared in another textstyle
k
That's my question though. How do you animate from italic to bold? From monospace to non monospace (different shapes of characters)? How do you animate a multi-line text where switching the font results in a different number of lines as words shift across lines?
v
To be honest, I do not know and possibly this is hard to implement. What I would like to achieve is something similar with autosizing textview. So, I do not want to bother with different fonts, etc. This autosizing needs to be implemented based on a gesture. Probably, I could do it by defining every animated value by hand, but this seems counterproductive
c
Do you have a video example of what you'd like to achieve?
d
I'd love to see a mock for the autosizing textview that you have in mind as well, if you don't mind sharing. 🙂 Maybe it's a use case that we could support if we could understand it better.
s
@Anastasia [G] fyi
Text Animation is not something we checked. It is Pandora's box as Kirill said and has performance issues.
v
I made a poc. Indeed I feel that is not an eye-catching animation. Additionally, I think that I have to write a lot of boilerplate to achieve it :s
d
This looks kind of like a shared element case. Given that we know the initial size and can look ahead for target size of the text layout, I wonder if there's anything we can do with that additional info to reduce the performance cost.
Also in terms of visual, I'm not sure resizing font size every frame would produce the most smooth visual transform. Cross fade might look better.
v
Thank you for you response! I ll give crossfade a try
z
Also fyi variable fonts are a lot more friendly to animating between styles, but android/compose support for them is pretty limited still and most fonts don't support it anyway
👍 2