Alex
05/21/2021, 5:05 PMAlex
05/21/2021, 5:05 PMAlex
05/21/2021, 5:06 PMAlex
05/21/2021, 5:06 PMAlex
05/21/2021, 5:07 PMrepeat(11) { index ->
Row {
Text(text = "${index + 1}.")
Spacer(modifier = Modifier.size(4.dp))
Text(text = "Text content")
}
}
Alex
05/21/2021, 5:08 PMHalil Ozercan
05/21/2021, 5:39 PMAlex
05/21/2021, 5:43 PMonGloballyPositioned
but then it will still render the text.. is there a way to only measure a composables size without drawing it?Halil Ozercan
05/21/2021, 5:44 PMSubcomposeLayout
. onGlobalPositioned
, onSizeChanged
and etc. will make you lose a frame.Jan Skrasek
05/21/2021, 6:11 PMnglauber
05/23/2021, 3:38 AMAlex
05/23/2021, 7:34 AMAlex
05/23/2021, 8:33 AMprivate object BulletPlaceables
private object ContentPlaceables
SubcomposeLayout(
modifier = modifier,
) { constraints ->
val maxBulletWidth = subcompose(BulletPlaceables) {
lines.forEachIndexed { index, _ -> bullet(index) }
}.map {
it.measure(constraints).width
}.maxByOrNull {
it
}?.let { maxWidth ->
// +1 to offset rounding errors during the conversion
with(LocalDensity.current) { ((maxWidth + 1) / density).dp }
} ?: 0.dp
// Measure the actual content
val contentPlaceable: Placeable = subcompose(ContentPlaceables) {
// This is the actual content I was rendering before, just now we know the maximum bullet size so we can use it
Column(
modifier = modifier,
) {
lines.forEachIndexed { index, lineContent ->
BulletListEntry(
style = style,
bullet = { bullet(index) },
bulletWidth = maxBulletWidth,
content = lineContent,
)
if (index != lines.lastIndex) {
Spacer(modifier = Modifier.height(entrySpacing))
}
}
}
}
.first()
.measure(constraints)
layout(contentPlaceable.width, contentPlaceable.height) {
contentPlaceable.placeRelative(0, 0)
}
}
nglauber
05/23/2021, 11:49 AMSubcomposeLayout
I’ll check it out 😉nglauber
05/23/2021, 1:37 PM