Could you explain how this works? I don't understand why this wouldn't trigger a recomposition 🙂
e
Elyes Mansour
03/14/2025, 9:18 AM
Sure thing 🙂
The regular size modifiers affect the composition phase, which causes too many recompositions when animating a composable's size through them, and possibly causing performance issues.
To avoid this, we'd have to update the size during the layout phase instead using the
layout
modifier, but that code can be cumbersome to write every time.
So I decided to just write these handful of modifiers that do the heavy lifting for us and are as easy to use as the regular ones we're used to.
The only difference is that they only animate the size during the layout phase without causing performance issues.
The reason why they can animate the changes during the layout phase instead of composition phase, is because the state read is deferred thanks to passing a lambda instead of the direct state value.
👍 1
j
Jonas B
03/14/2025, 9:20 AM
Thats great. Thanks for the explanation!
o
Oleg
03/15/2025, 9:41 AM
It looks like the offset modifier works like this
e
Elyes Mansour
03/15/2025, 9:51 AM
Yep, the offset modifier has a lambda parameter to defer the state read to the draw phase.