Assigned
Status Update
Comments
os...@google.com <os...@google.com>
os...@google.com <os...@google.com> #2
Hi, it is indeed a bug.
Could you try the ConstraintSet pattern in the meantime? Seems to be working properly, here's an equivalent example:
@Composable
fun ItemCard(
name: String,
description: String?,
modifier: Modifier = Modifier,
) {
val constraintSet = remember(name, description) {
ConstraintSet {
val (image, title, optionalDescription) = createRefsFor("image", "title", "optional")
constrain(image, title, optionalDescription) {
linkTo(parent.start, parent.end)
}
createVerticalChain(image, title, optionalDescription, chainStyle = ChainStyle.Packed)
}
}
ConstraintLayout(
constraintSet = constraintSet,
modifier = modifier.size(200.dp)
) {
Box(
modifier = Modifier
.size(100.dp)
.background(Color.Red)
.layoutId("image"),
)
Text(
text = name,
modifier = Modifier
.layoutId("title")
.padding(start = 16.dp, top = 8.dp, end = 16.dp),
)
description?.let {
Text(
text = it,
modifier = Modifier.layoutId("optional"),
)
}
}
}
Description
We updated from
androidx.constraintlayout:constraintlayout-compose
from1.0.1
to1.1.0
and noticed behavior changes in our previously working ui components.The code looks like this:
So the
optionalTitle
reference will only be set to the Text composable if description is not null. With Version 1.0.1 this was not breaking the layout. With 1.1.0 the chain will behave unexpected and the ui breaks (see attached screenshots).