New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Foundation Layout

consumeWindowInsets

Common

Consume insets that haven't been consumed yet by other insets Modifiers similar to [windowInsetsPadding] without adding any padding.

This can be useful when content offsets are provided by [WindowInsets.asPaddingValues]. This should be used further down the hierarchy than the [PaddingValues] is used so that the values aren't consumed before the padding is added.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation-layout:1.7.0-beta04")
}

Overloads

@Stable
fun Modifier.consumeWindowInsets(insets: WindowInsets)
@Stable
fun Modifier.consumeWindowInsets(paddingValues: PaddingValues)

Code Examples

consumedInsetsSample

@Sampled
fun consumedInsetsSample() {
    class SampleActivity : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            WindowCompat.setDecorFitsSystemWindows(window, false)
            super.onCreate(savedInstanceState)
            setContent {
                Box(Modifier.padding(WindowInsets.navigationBars.asPaddingValues())) {
                    Box(Modifier.consumeWindowInsets(WindowInsets.navigationBars)) {
                        // app content
                    }
                }
            }
        }
    }
}

consumedInsetsPaddingSample

@Sampled
fun consumedInsetsPaddingSample() {
    class SampleActivity : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            WindowCompat.setDecorFitsSystemWindows(window, false)
            super.onCreate(savedInstanceState)
            setContent {
                with(LocalDensity.current) {
                    val paddingValues = PaddingValues(horizontal = 20.dp)
                    Box(
                        Modifier
                            .padding(paddingValues)
                            .consumeWindowInsets(paddingValues)
                    ) {
                        // app content
                    }
                }
            }
        }
    }
}