Mario
02/17/2025, 3:06 PMrequiredSize
that's greater than the parent unexpectedly causes the child to be centered.
If the Box
is smaller, it's placed at the top left. But if it's greater, it's centered (i.e., you can't see the yellow anymore). See the pictures.
@Preview("Test", device = "spec:width=500dp,height=500dp,dpi=240")
@Composable
private fun ReproPreview() {
val colorStops = arrayOf(
0.0f to Color.Yellow,
0.2f to Color.Red,
1f to Color.Blue
)
BoxWithConstraints(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.TopStart
) {
Box(
modifier = Modifier
.background(Brush.horizontalGradient(colorStops = colorStops))
.requiredSize(height = maxHeight * 2, width = maxWidth * 2)
// Also happens with `offset`
.absoluteOffset(0.dp, 0.dp)
)
}
}
Stylianos Gakis
02/17/2025, 3:09 PMwrapContentSize()
and provide the alignment you want in there.Mario
02/17/2025, 3:11 PMwrapContentSize
after the requiredSize
, which caused something weird. This behavior caught me off-guard, though -- should it be the default?Mario
02/17/2025, 3:11 PMMario
02/17/2025, 3:13 PMStylianos Gakis
02/17/2025, 3:19 PMkecaroh
02/18/2025, 8:37 AM