Hi everyone! I'm migrating an app to Jetpack Compo...
# compose
m
Hi everyone! I'm migrating an app to Jetpack Compose and currently I'm just adding
ComposeView
as the root view of my Fragments. However, the Activity hosting all Fragments does not call
WindowCompat.setDecorFitsSystemWindows(window, false)
and thus I have a problem inside the
ComposeView
hosted in my Fragments -> insets are not taken into account. When calling
WindowInsets.statusBars.asPaddingValues()
it returns 0. However, I want my
TopAppBar
to have some padding to be below the Android status bar. I know we're more and more migrating to Compose progressively, someone might eventually have encountered this problem with the insets. Thank you in advance!
g
Hi, here's what I use as the base of each Compose UI inside fragments
Copy code
@Composable
fun EdgeToEdge(
    backgroundColor: Color,
    content: @Composable BoxScope.() -> Unit,
) {
    Box(
        modifier = Modifier
            .background(backgroundColor)
            .fillMaxSize()
            .statusBarsPadding()
            .navigationBarsPadding(),
        content = content
    )
}
Hope this helps 😊
m
I tried it directly on my
TopAppBar
like this:
Copy code
TopAppBar(modifier = Modifier.statusBarsPadding())
But does not seem to work 😕 My AppBar is under the status bar which is kinda ugly and the buttons on it are inaccessible