admin管理员组文章数量:1392002
I have this extension function written over a modifier
fun Modifier.ignoreParentPadding(padding: Dp) = this.layout { measurable, constraints ->
val placeable = measurable.measure(
constraints.copy(
maxWidth = constraints.maxWidth + (padding.roundToPx() * 2),
),
)
layout(placeable.width, placeable.height) {
placeable.place(0, 0)
}
}
This is how i use it
ComposeMessagePart(
modifier = Modifier.ignoreParentPadding(smallMediumUnit),
messageOwner = selectedMessageOwner,
)
I have noticed that there are unnecessary compositions that occur for ComposeMessagePart composable , and it reports that each time it recieves a different LayoutElement .
I do not see this happen if i do not use the extension function rather directly do the following
ComposeMessagePart(
modifier = Modifier.layout { measurable, constraints ->
val placeable = measurable.measure(
constraints.copy(
maxWidth = constraints.maxWidth + (smallMediumUnit.roundToPx() * 2),
),
)
layout(placeable.width, placeable.height) {
placeable.place(0, 0)
}
},
messageOwner = selectedMessageOwner,
)
The code above works fine and no unneccesary recomposition is seen. I have not yet being able to rationalize as to why do recompositions happen in the ComposeMessagePart if the same code runs as an extension vs in-place .
Any idea folks ?
本文标签: android jetpack composeModifier extension causes unnecessary recompositionsStack Overflow
版权声明:本文标题:android jetpack compose - Modifier extension causes unnecessary recompositions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744715000a2621350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论