I’m trying to wrap a xml view in compose. It’s ins...
# compose
c
I’m trying to wrap a xml view in compose. It’s inside the `content`part of a Scaffold. It does not respect the bounds of the view, even if i set clipToOutline = true. The red background is correct, so the size of the composable is correct Any ideas?
Copy code
AndroidView(
        modifier = Modifier
            .background(Color.Red)
            .statusBarsPadding()
            .fillMaxSize(),
        factory = { context ->
            HomeView(context).apply {
                clipToOutline = true
            }
        }
    )
This happen’s even in a basic example, no bottomnavigation, scaffold or anything.
Copy code
DefaultTheme {
    Box(Modifier.height(500.dp)) {
        AndroidView(
            modifier = Modifier
                .matchParentSize()
                .background(androidx.compose.ui.graphics.Color.Red),
            factory = { context ->
                HomeView(context).apply {
                    clipToOutline = true
                }
            }
        )
    }
}
m
I haven't looked into it in detail, but if you use Scaffold, you need to use contentPadding on the content side.
c
I am 🙂 and it happens even without the scaffold. My second example is the only compose code, called directly in setContent in the activity
m
and try to apply Modifier.clipToBounds() to AndroidView composable.
c
That made no difference unfortunately. If i create an empty view inside the factory lambda instead of instantiating HomeView, then it works. So it’s something about that view, I think
m
hmm.. that's weird. You mean that HomeView is drawn over the Composable range, right..?
c
yes, it takes up the entire screen
Ah, I’m an idiot. HomeView was inflating into rootView 🤦‍♂️
m
Oh...😅
Issue closed 👍
c
Yep! thanks for the help 🙂
🙇‍♂️ 1