What is the difference between `Modifier.height` a...
# compose
r
What is the difference between
Modifier.height
and
Modifier.requiredHeight
?
g
Before we had height and preferredHeight. Which were renamed to requiredHeight (height) and height (preferredHeight)
a
This code and image illustrates the difference pretty well
Copy code
Column(Modifier.width(50.dp).background(Color.Red)) {
    Box(Modifier.size(60.dp).background(Color.Green))
    Box(Modifier.requiredSize(60.dp).background(Color.Blue))
}
👍 2
b
@Rafs you can check for the javadoc here https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]/androidx/compose/foundation/layout/Size.kt;l=1?q=Size.kt&sq= height
Declare the preferred height of the content to be exactly heightdp. The incoming measurement Constraints may override this value, forcing the content to be either smaller or larger.
requiredHeight
Declare the height of the content to be exactly [height]dp. The incoming measurement
[Constraints] will not override this value.
d
height
is something which can change if the parent composable
height
becomes less than defined
height
whereas
requiredHeight
doesn't change irrespective of parent composable's
height
, view will go outside the border
r
Thank you all for your responses.