consumeWindowInsets
Common
Modifier in Compose Foundation Layout
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.8.0-alpha04")
}
Overloads
@Stable
fun Modifier.consumeWindowInsets(insets: WindowInsets): Modifier
@Stable
fun Modifier.consumeWindowInsets(paddingValues: PaddingValues): Modifier
Code Examples
consumedInsetsSample
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
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
}
}
}
}
}
}