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

Evgeny Taskaev

02/11/2022, 7:05 PM
Hello everyone) Tell me, is there some practical example when you need to use requiredSize modifier, but not size modifier. And is requiredSize always worth using when exact dimensions are needed?)
a

Albert Chang

02/12/2022, 3:46 AM
Modifier.requiredSize()
is only needed if you want to override the size specified by
Modifier.size()
before in a modifier chain.
Modifier.size(10.dp).size(5.dp)
makes the size 10dp and
Modifier.size(10.dp).requiredSize (5.dp)
makes the size 5dp.
today i learned 1
Or override the size coming from constraints, e.g. making an item 10dp in a 5dp box.
2
a

Albert Chang

02/12/2022, 4:21 PM
@Chris Sinco [G] I believe in that case
Modifier.size(24.dp)
will also work. Btw this is the bug.
👍 1
c

Chris Sinco [G]

02/12/2022, 4:39 PM
Ahhh that makes more sense. Required size was the workaround there 🤷🏻‍♂️
a

Afzal Najam

02/15/2022, 4:42 AM
Another example is if you want to make a FloatingActionButton bigger than the size allowed by
Scaffold
(its parent), maybe for a transition animation. No matter how high of a value you put in
size
, it will still stay a weird rounded rectangle and not exceed a certain size. But if you use
requiredSize
, it will go bigger.
a

Albert Chang

02/15/2022, 4:55 AM
Yeah that’s exactly the second use case above.