https://kotlinlang.org logo
j

Joseph D

03/09/2021, 3:58 PM
I've seen there's no API for reading for example a Modifier's size, what's the reason behind that? Let's say I need to read it because some other value depends on it.
a

Adam Powell

03/09/2021, 4:02 PM
There is
Modifier.onSizeChanged
but you should use caution not to create circular data dependencies based on it. Acting on an output of layout (such as element size) during composition should always make you think twice.
j

Joseph D

03/09/2021, 4:37 PM
I see. So I guess that basing a Text's fontSize on the Modifier's size is wrong. What would be instead the right approach? Or maybe there's a way to automatically have the fontSize dependant of the size?
a

Adam Powell

03/09/2021, 7:05 PM
I think @cb might have done some work with this use case, cc @Siyamed too
j

Joseph D

03/09/2021, 8:57 PM
This solution seems to fit my case yet it would be nice an OOTB solution
s

Siyamed

03/09/2021, 10:40 PM
Joseph are you trying to implement autosize?
j

Joseph D

03/09/2021, 10:56 PM
I am, Siyamed
s

Siyamed

03/09/2021, 11:56 PM
Implementing a composable with layout and using paragraph to fit into the size given sounds like a solution to me to make things in one pass.
s

Shakil Karim

05/25/2021, 9:11 PM
@Siyamed is there any example code for AutoTextSize based on what your are describing here ?
2 Views