If I am drawing a composable which happens to be a...
# compose
s
If I am drawing a composable which happens to be a child of another composable which is a surface and therefore clips its children, is there any way I can no respect that and draw outside of those bounds anyway? Even if that is done through any graphics layers tricks or whatever, I don't mind. I am mostly curious if it's possible in any way.
j
Have you tried a manual draw modifier before your
Modifier.clipToBounds()
?
Copy code
Box(Modifier.fillMaxSize()) {
    Box(
        modifier = Modifier
            .drawBehind {
                drawRect(
                    color = Color.Green,
                    topLeft = Offset(x = 10.dp.toPx(), y = 0F),
                    size = Size(400.dp.toPx())
                )
            }
            .clipToBounds()
    ) {
        Box(Modifier.size(300.dp)
            .background(Color.Yellow)
            .size(300.dp))
    }
}
This code produces the following result:
s
I am sorry I probably didn't explain this very well. My child wants to render outside of the parent bounds. And the child is way further down the line compared to the parent which clips. It would not be possible for me to put something before the clip modifier. In particular it's a TopAppBar which is that clipping surface, and I want to put some child in there which goes outside of the bounds of that TopAppBar by doing
wrapContentHeight(unbounded = true)
e
You shouldnt be using Surface as surface clips. Its not possible to ignore that as clipping is a draw operation.
s
Yeap, that surface in this context is on the TopAppBar itself, which is done so that you get the correct shape and the correct background color along with the correct LocalContentColor. Removing that surface from all of my TopAppBars in the entire app might be possible, but probably not the first thing I'd like to do.