androidandroid-jetpack-composedialogwindowinsets

Window insets on dialogs jetpack compose


I have a app our company puts out and I can't seem to get the insets right for dialogs for Android 15 edge to edge. We have a NAvHost that navigates sometimes to composables and sometimes to dialogs. On regular compose screens:

NavHost(navController = navController, startDestination = MY_ROUTE") {
    
composable
(
        route = "my_route_to_composable"
    ) { backStackEntry ->
       MyComposable() 
    }
}

Things are fine. However, when we navigate to dialogs:

NavHost(navController = navController, startDestination = MY_ROUTE") {
    
dialog
(
        route = "my_route_to_dialog"
    ) { backStackEntry ->
       MyDialog()
   }
}

It does not respect the .safeContentPadding() on the Scaffold:

fun MyDialog() {

   Scaffold(
       modifier = Modifier
        .fillMaxSize(),
        .safeContentPadding(),
       contentWindowInsets = WindowInsets(0,0,0,0),
   ) { contentPadding ->
      Box(modifier = Modifier.padding(contentPadding) {

       .....
      }

   }
}

However, this is only for Pixel phones. On Samsungs we are hunky dory. To fix it on on Pixel phones, we still have to add a space at the bottom of the screen so the bottom buttons don't get cut off.

Any advice? I feel like Ive combed through the documentation hundreds of times.


Solution

  • I can think of 2 possible reasons if I may:

    1. Dialogs do not inherit insets automatically. Unlike full-screen composables, dialogs do not automatically respect safeContentPadding(). You might need to manually apply WindowInsets. Could you log the insets inside the dialog to confirm/disprove this?

    2. Scaffold inside a Dialog behaves differently than in a full screen Composable. The Scaffold insets inside a dialog do not behave as expected compared to a normal Composable, I also had the experience.

    If it doesn't help, then I think it would come to different implementations of AOSP used by the manufacturers.