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

Vaios Tsitsonis

05/20/2022, 2:03 PM
is there any way to animate between two textstyles?
k

Kirill Grouchnikov

05/20/2022, 2:32 PM
How would you expect this to work across completely different font families, multiline texts, etc?
v

Vaios Tsitsonis

05/20/2022, 2:43 PM
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

Kirill Grouchnikov

05/20/2022, 2:45 PM
There's way more to
TextStyle
than just font size
v

Vaios Tsitsonis

05/20/2022, 2:47 PM
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

Kirill Grouchnikov

05/20/2022, 2:54 PM
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

Vaios Tsitsonis

05/20/2022, 3:06 PM
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

Chris Sinco [G]

05/20/2022, 4:21 PM
Do you have a video example of what you'd like to achieve?
d

Doris Liu

05/20/2022, 7:55 PM
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

Siyamed

05/20/2022, 8:09 PM
@Anastasia [G] fyi
Text Animation is not something we checked. It is Pandora's box as Kirill said and has performance issues.
v

Vaios Tsitsonis

05/20/2022, 9:19 PM
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

Doris Liu

05/20/2022, 9:57 PM
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

Vaios Tsitsonis

05/21/2022, 7:26 AM
Thank you for you response! I ll give crossfade a try
z

Zach Klippenstein (he/him) [MOD]

05/22/2022, 2:01 PM
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
8 Views