value to affect placement of layout children, will it impact performance in some way? Is there some in-depth look of what is cached and when during layout in compose?
E.g.
Copy code
fun MyLayout(x: Int) {
Layout(content = {...}) { m, c ->
...
layout(w,h) { child.placeRelative(x, 0) }
}
}
fun Screen() {
// or x is from pointerInput + stored in State
val x by animateValue(300)
MyLayout(x)
}
s
Stylianos Gakis
08/06/2022, 11:35 AM
I don't think there's anything magic happening to optimize this by default, but I believe there is an opportunity to do one thing here.
Looking at the docs here https://developer.android.com/jetpack/compose/performance#defer-reads you can get an idea of how to defer that read to only happen inside the
layout {}
lambda by passing in a lambda fetching that value instead of the value itself. That could mean that you can only do a re-layout and not an entire recomposition.
I haven't tried doing that myself, not sure if it'd work, I'm only basing it off of my understanding of the docs so please if you do try it tell me how it goes.
z
Zach Klippenstein (he/him) [MOD]
08/06/2022, 3:11 PM
Generally avoiding recomposition in animations is desirable, and yep, passing a lambda would be the typical thing to do here.