Lucas Kivi
01/12/2023, 4:49 PMDp
height.robercoding
01/12/2023, 4:54 PMLayout
phase
Use the Modifier.layout{ }
and defer the read inside that lambda, then convert dp
to px
and voila, skipping the recomposition when animating the height or any other frequently-changing value for the layout phase!
This is what I did for the width
in the past:
fun Modifier.width(widthProvider: () -> Dp): Modifier {
return this.layout { measurable, constraints ->
val width = widthProvider().toPx().toInt()
val placeable = measurable.measure(constraints.copy(minWidth = width, maxWidth = width))
layout(placeable.width, placeable.height) {
placeable.placeRelative(0, 0)
}
}
}
Lucas Kivi
01/12/2023, 4:55 PMrobercoding
01/12/2023, 5:05 PMLucas Kivi
01/12/2023, 5:06 PMLucas Kivi
01/12/2023, 5:07 PM