rob42
07/25/2024, 3:18 PMModifier.myModifier()
would be invoked on recomposition when it takes parameters, but not when no parameters are taken?rob42
07/25/2024, 3:19 PMfun Modifier.layoutWithParam(param: String) = layout { measurable, constraints ->
println("layoutWithParam: $param") // invoked frequently
val placeable = measurable.measure(constraints)
layout(placeable.width, placeable.height) {
placeable.place(0,0)
}
}
This is the custom modifier in question, which is invoked whenever the composable recomposes.
Whereas this modifier is only invoked once:
fun Modifier.layoutNoParam() = layout { measurable, constraints ->
println("layoutNoParam") // invoked only once
val placeable = measurable.measure(constraints)
layout(placeable.width, placeable.height) {
placeable.place(0,0)
}
}
rob42
07/25/2024, 3:20 PMModifier.layoutWithParam("foo")
Zach Klippenstein (he/him) [MOD]
07/25/2024, 4:35 PM@Composable
code in your modifier so the compose compiler plugin doesn’t touch it.Zach Klippenstein (he/him) [MOD]
07/25/2024, 4:37 PMrob42
07/26/2024, 1:31 PMZach Klippenstein (he/him) [MOD]
07/26/2024, 5:08 PMZach Klippenstein (he/him) [MOD]
07/26/2024, 5:11 PM