what’s the equivalent of “a view that i need to tr...
# compose
o
what’s the equivalent of “a view that i need to treat as a bounding box for a single icon” ? could be Column or Row or even Box really, right?
this bounding box would be like 40dp for example, and the icon is 24 in the center
s
Could be
Copy code
Box(Modifier.size(40.dp) {
  Icon(Modifier.align(Alignment.Center).size(24.dp))
}
If this happens to be a clickable one, you can use the built-in solution of
Copy code
IconButton(onClick = {}) {
  Icon()
}
Since IconButton knows how to size itself to comply with accessibility standards plus it sets its content as
contentAlignment = Alignment.Center
automatically.
o
Yes that's what I did thanks !
a
Or just
Icon(modifier = Modifier.size(40.dp).wrapContentSize(align = Alignment.Center).size(24.dp))
.
s
TIL
.wrapContentSize
exists 🤯 Thanks Albert!
o
that’s cool @Albert Chang but how does that work exactly, how did that become equivalent to a Box with modifier size 40 and inside an Icon size 24 ?
a
Modifier.wrapContentSize()
aligns the content (including the modifiers coming after it) within the min size constraints passed in (including the modifiers coming before it).