https://kotlinlang.org logo
Title
t

Travis Griggs

04/05/2023, 5:35 PM
Is there anything like the iOS "shrink font size" for Texts? Basically, if it doesn't fit, you can specify a scalar or minimum font size and it will try to use smaller and smaller fonts until it reaches that limit, and then applies whatever visual overflow handling you want
r

romainguy

04/05/2023, 6:13 PM
We do not support this unfortunately, at least not yet. It’s a feature from the View system (https://developer.android.com/develop/ui/views/text-and-emoji/autosizing-textview) that has yet to make it into Compose.
t

Travis Griggs

04/05/2023, 6:52 PM
:thank-you-color: I'll keep an eye out for when it makes it over.
Just out of design curiosity, would it be likely that TextOverflow picked up this additonal data so that all of that was in one place? Or is it more likely it would be added as another optional parameter to the Text() composable?
r

romainguy

04/05/2023, 6:55 PM
No idea. Prob a separate parameter since you’ll want to specify min/max font size
s

Siyamed

04/05/2023, 8:43 PM
Adding to text overflow is interesting idea will keep that in mind, but possibly would require another config as Romain mentioned.
h

Halil Ozercan

04/05/2023, 11:43 PM
In the meantime, you can refer to this example for ideas on how to achieve that in Compose https://gist.github.com/halilozercan/d1468efa45c4e9a71907623e41c2ccb7
a

Albert Chang

04/06/2023, 7:31 AM
@Halil Ozercan Is the
flag
necessary to trigger redraw? I have a auto shrink text implementation here in which I'm also using
Ref<TextLayoutResult>
but I'm not manually triggering redraw, and it seems to work well. Correct me if I'm wrong but I think recomposition or relayout will always result in redraw so it doesn't seem needed to manually trigger redraw.
h

Halil Ozercan

04/06/2023, 8:07 PM
Yes in many cases a recomposition triggers relayout and redraw but that behavior is not guaranteed. https://developer.android.com/jetpack/compose/phases#:~:text=Depending%20on%20the%20result%20of,the%20layout%20won't%20change.