Hi everyone. I have a quick question about clippin...
# compose
s
Hi everyone. I have a quick question about clipping the content by composables. If I'm not mistaken, composables don't clip content by default, but in code bellow it seems it clips content of the inner box. Am I doing something wrong? (code in thread)
Copy code
@Composable
fun MyComposable() {
    Box(
        modifier = Modifier
            .size(100.dp)
            .background(Color.LightGray)
            .offset(10.dp, (-10).dp),
        contentAlignment = Alignment.TopStart
    ) {
        Box(
            modifier = Modifier
                .size(300.dp)
                .background(Color.DarkGray),
            contentAlignment = Alignment.TopStart
        ) {
            Text(text = "test")
        }
    }
}
z
That’s not really clipping – the
background
modifier simply only draws within its bounds. If you want to change the bounds used for the background modifier, change its position in the modifier chain.
s
oh I see my mistake. I need to use
requiredHeight
instead. The
height
modifier declares the preferred height and can be overridden by incoming measurement constraints. Thanks for your help Zach