Known direct subclasses
MutableWindowInsets

A WindowInsets whose values can change without changing the instance.


A representation of window insets that tracks access to enable recomposition, relayout, and redrawing when values change. These values should not be read during composition to avoid doing composition for every frame of an animation. Use methods like Modifier.windowInsetsPadding, Modifier.systemBarsPadding, and Modifier.windowInsetsTopHeight for Modifiers that will not cause recomposition when values change.

Use the WindowInsets.Companion extensions to retrieve WindowInsets for the current window.

Summary

Nested types

Public functions

Int
getBottom(density: Density)

The space, in pixels, at the bottom of the window that the inset represents.

Cmn
Int
getLeft(density: Density, layoutDirection: LayoutDirection)

The space, in pixels, at the left of the window that the inset represents.

Cmn
Int
getRight(density: Density, layoutDirection: LayoutDirection)

The space, in pixels, at the right of the window that the inset represents.

Cmn
Int
getTop(density: Density)

The space, in pixels, at the top of the window that the inset represents.

Cmn

Extension functions

WindowInsets

Returns a WindowInsets that has values of this, added to the values of insets.

Cmn
PaddingValues

Convert a WindowInsets to a PaddingValues and uses LocalDensity for DP to pixel conversion.

Cmn
PaddingValues

Convert a WindowInsets to a PaddingValues and uses density for DP to pixel conversion.

Cmn
WindowInsets

Returns the values in this WindowInsets that are not also in insets.

Cmn
WindowInsets

Returns a WindowInsets that eliminates all dimensions except the ones that are enabled.

Cmn
WindowInsets

Returns a WindowInsets that has the maximum values of this WindowInsets and insets.

Cmn

Public functions

getBottom

fun getBottom(density: Density): Int

The space, in pixels, at the bottom of the window that the inset represents.

getLeft

fun getLeft(density: Density, layoutDirection: LayoutDirection): Int

The space, in pixels, at the left of the window that the inset represents.

getRight

fun getRight(density: Density, layoutDirection: LayoutDirection): Int

The space, in pixels, at the right of the window that the inset represents.

getTop

fun getTop(density: Density): Int

The space, in pixels, at the top of the window that the inset represents.

Extension functions

fun WindowInsets.add(insets: WindowInsets): WindowInsets

Returns a WindowInsets that has values of this, added to the values of insets. For example, if this has a top of 10 and insets has a top of 5, the returned WindowInsets will have a top of 15.

@Composable
fun WindowInsets.asPaddingValues(): PaddingValues

Convert a WindowInsets to a PaddingValues and uses LocalDensity for DP to pixel conversion. PaddingValues can be passed to some containers to pad internal content so that it doesn't overlap the insets when fully scrolled. Ensure that the insets are consumed after the padding is applied if insets are to be used further down the hierarchy.

import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.lazy.LazyColumn

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            LazyColumn(
                contentPadding = WindowInsets.navigationBars.asPaddingValues()
            ) {
                // items
            }
        }
    }
}
fun WindowInsets.asPaddingValues(density: Density): PaddingValues

Convert a WindowInsets to a PaddingValues and uses density for DP to pixel conversion. PaddingValues can be passed to some containers to pad internal content so that it doesn't overlap the insets when fully scrolled. Ensure that the insets are consumed after the padding is applied if insets are to be used further down the hierarchy.

import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.lazy.LazyColumn

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            LazyColumn(
                contentPadding = WindowInsets.navigationBars.asPaddingValues()
            ) {
                // items
            }
        }
    }
}
fun WindowInsets.exclude(insets: WindowInsets): WindowInsets

Returns the values in this WindowInsets that are not also in insets. For example, if this WindowInsets has a WindowInsets.getTop value of 10 and insets has a WindowInsets.getTop value of 8, the returned WindowInsets will have a WindowInsets.getTop value of 2.

Negative values are never returned. For example if insets has a WindowInsets.getTop of 10 and this has a WindowInsets.getTop of 0, the returned WindowInsets will have a WindowInsets.getTop value of 0.

fun WindowInsets.only(sides: WindowInsetsSides): WindowInsets

Returns a WindowInsets that eliminates all dimensions except the ones that are enabled. For example, to have a WindowInsets at the bottom of the screen, pass WindowInsetsSides.Bottom.

fun WindowInsets.union(insets: WindowInsets): WindowInsets

Returns a WindowInsets that has the maximum values of this WindowInsets and insets.