https://kotlinlang.org logo
#compose
Title
# compose
v

Victor Yakovlev

09/07/2020, 6:47 PM
How to set height to
fillMaxHeight
inside component where height is
wrapContentHeight
?
I try set
preferredHeight(IntrinsicSize.Min)
for parent, but if use
CoilImage
inside parent we have exception:
Intrinsic measurements are not currently supported by SubcomposeLayout
a

Adam Powell

09/07/2020, 6:58 PM
Those two should be fine to use together
v

Victor Yakovlev

09/07/2020, 7:06 PM
Not work, also have exception
Intrinsic measurements are not currently supported by SubcomposeLayout
a

Adam Powell

09/07/2020, 7:49 PM
fillMaxHeight should work fine inside wrapContentHeight
v

Victor Yakovlev

09/08/2020, 5:09 AM
Ok, I prepared sample
LazyColumnFor(items = listOf(1, 2, 3)) { item ->
Column(modifier = Modifier.fillMaxWidth()) {
Row(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.preferredHeight(IntrinsicSize.Min)
.padding(16.dp),
verticalGravity = Alignment.CenterVertically
) {
Box(
modifier = Modifier
.width(5.dp)
.fillMaxHeight(),
backgroundColor = Color.Cyan
)
Column(
modifier = Modifier.padding(start = 8.dp)
) {
ProvideEmphasis(emphasis = EmphasisAmbient.current.high) {
Text(
text = "App Name $item",
style = MaterialTheme.typography.subtitle1,
)
}
ProvideEmphasis(emphasis = EmphasisAmbient.current.medium) {
Text(
text = "App description",
style = MaterialTheme.typography.body2
)
}
}
}
Divider(
modifier = Modifier.padding(horizontal = 8.dp),
color = Color.DarkGray
)
}
}
It's basic sample
If I add
preferredHeight(IntrinsicSize.Min)
to Row
If removed
preferredHeight(IntrinsicSize.Min)
and add
CoilImage
as last child of Row
Copy code
CoilImage(
    data = "<https://picsum.photos/seed/123/300/300>",
    contentScale = ContentScale.Crop,
    modifier = Modifier
        .width(50.dp)
        .height(50.dp)
)
If add
preferredHeight(IntrinsicSize.Min)
to Row and add
CoilImage
as last child I have
java.lang.IllegalStateException: Intrinsic measurements are not currently supported by SubcomposeLayout
v

Victor Yakovlev

09/08/2020, 6:48 PM
@Adam Powell
a

Adam Powell

09/08/2020, 6:56 PM
I see, so it is less about a wrap-content container and more about a container that has an unlimited max height
the most straightforward way to approach this is likely to be to add a modifier that draws the cyan indicator to the side of the Column that contains the text, or alternatively to the Row that holds everything
you want the size of the cyan bar to be the measured height of the content
take a look at the various border-related modifiers to see how they are implemented, a similar approach will likely be successful