First, disable platform-specific default insets being applied in the app.
- For IOS you need to disable safe area paddings being applied by the Switft UI by adding the following line in
iosApp/iosApp/ContentView.swift file.
// iosApp/iosApp/ContentView.swift
struct ContentView: View {
var body: some View {
ComposeView()
.ignoresSafeArea(edges: .all) // Add this line
.ignoresSafeArea(.keyboard)
}
}
- For Android Make sure to call
enableEdgeToEdge() in your Activity's onCreate.
// MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge() // Add this
setContent {
// composables
}
}
Your app will now start drawing content behind the top and bottom bar; Now you can use WindowInsets API from Compose to apply correct padding from within compose.
@Composable
MyScreen() {
Box(
Modifier
.background(Color.Red)
.windowInsetsPadding(WindowInsets.safeDrawing)
) {
// Content goes here
}
}