Search code examples
androidandroid-jetpack-compose

Android compose cope with windows insets for tablets and phones


I am having issues with coping with windows insets in my current Android Jetpack Compose project.

When I install my application on a phone the padding is fine and all my compose screens display all their content fine.

However when I install the same application on my Samsung tablet (which has a software bottom navigation strip) all my applications screens have the bottom content hidden.

I have been able to fix on tablet by using windows insets however fix is also affecting the application on my phone.

How can i detect when to "fix" the windows insets for this situation and any others that i have not encountered yet?

How can I detect/react to the location of all windows insets on any device?


Solution

  • You should use a Scaffold in your composables. Even if you don't need any of it's modules, it provides a ContentPadding variable showing you the insets that should be used:

    Scaffold(/* ... */) { contentPadding ->
        // Screen content
        Box(modifier = Modifier.padding(contentPadding)) { /* ... */ }
    }
    

    You can then pass that content padding to your container composable as a Modifier.padding()