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

bohregard

08/02/2020, 5:03 PM
Ok y’all, how do you draw a view that has no children but has a color background?
Copy code
Surface(
    color = Color(0xFFFF0000),
    modifier = Modifier.width(5.dp).fillMaxHeight()
) {
    Text("")
}
I’ve got this, but if I remove the Text item the color isn’t drawn which is really all I care about
a

Archie

08/02/2020, 5:07 PM
You could use a
Box
instead.
f
b

bohregard

08/02/2020, 5:09 PM
Hmm that doesn’t work
Copy code
Box(
                        backgroundColor = MaterialTheme.colors.primary,
                        modifier = Modifier.width(5.dp).fillMaxHeight()
                    )
That doesn’t draw anything unless I add a child
hmm, I think the issue that I”m running into is that fillMaxHeight() must not know about the actual height of the item being drawn
if I hardcode a real height it’s fine
Copy code
Card(modifier = Modifier.fillMaxWidth().padding(10.dp)) {
                Row {
                    Box(
                        backgroundColor = MaterialTheme.colors.primary,
                        modifier = Modifier.width(5.dp).height(100.dp)
                    ) {}

                    Column(
                        modifier = Modifier.padding(start = 5.dp).fillMaxWidth().fillMaxHeight()
                    ) {
                        Text(
                            text = it.seriesName
                        )
                        Text(
                            text = it.title
                        )
                        Text(
                            text = LocalDateTime.ofInstant(it.airDateUtc, ZoneId.systemDefault())
                                .toString()
                        )
                    }
                }
            }
a

Archie

08/02/2020, 5:11 PM
the code you sent worked for me...
Copy code
Box(
    backgroundColor = MaterialTheme.colors.primary,
    modifier = Modifier.width(5.dp).fillMaxHeight()
)
worked just fine..
what compose version are you on?
b

bohregard

08/02/2020, 5:12 PM
dev15
a

Archie

08/02/2020, 5:14 PM
try specifying the height of the
Card
to say a fixed height or to wrap...
b

bohregard

08/02/2020, 5:17 PM
specifying the content size works (ie
height(100.dp)
) but wrap content size or wrap content height doesn’t work