# WindowInsets

# WindowInsets

Artifact: [androidx.compose.foundation:foundation-layout](https://developer.android.com/jetpack/androidx/releases/compose-foundation)  
[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/layout/WindowInsets.kt+class:androidx.compose.foundation.layout.WindowInsets)  
Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)
Common/AllAndroid/JVM
  - Cmn  

  ```
  interface WindowInsets
```  
Known direct subclasses  
[MutableWindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets)  

|------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [MutableWindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets) | A [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/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](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.ui.Modifier).windowInsetsPadding(androidx.compose.foundation.layout.WindowInsets)), [Modifier.systemBarsPadding](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.ui.Modifier).systemBarsPadding()), and [Modifier.windowInsetsTopHeight](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.ui.Modifier).windowInsetsTopHeight(androidx.compose.foundation.layout.WindowInsets)) for Modifiers that will not cause recomposition when values change.

Use the [WindowInsets.Companion](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets.Companion) extensions to retrieve [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) for the current window.

## Summary

|                                                              ### Nested types                                                               |
|---------------------------------------------------------------------------------------------------------------------------------------------|
| `object `[WindowInsets.Companion](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets.Companion) |

|                            ### Public functions                             |
|-----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getBottom](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getBottom(androidx.compose.ui.unit.Density))`(density: `[Density](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density)`)` The space, in pixels, at the bottom of the window that the inset represents.                                                                                                                                                                      | Cmn |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getLeft](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getLeft(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection))`(density: `[Density](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density)`, layoutDirection: `[LayoutDirection](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection)`)` The space, in pixels, at the left of the window that the inset represents.    | Cmn |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getRight](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getRight(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection))`(density: `[Density](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density)`, layoutDirection: `[LayoutDirection](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection)`)` The space, in pixels, at the right of the window that the inset represents. | Cmn |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getTop](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getTop(androidx.compose.ui.unit.Density))`(density: `[Density](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density)`)` The space, in pixels, at the top of the window that the inset represents.                                                                                                                                                                               | Cmn |

|                                             ### Extension functions                                              |
|------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)   | [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`.`[add](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#(androidx.compose.foundation.layout.WindowInsets).add(androidx.compose.foundation.layout.WindowInsets))`(insets: `[WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`)` Returns a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that has values of this, added to the values of [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).add(androidx.compose.foundation.layout.WindowInsets)).                                                                                                              | Cmn |
| [PaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues) | `@`[Composable](https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable) [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`.`[asPaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#(androidx.compose.foundation.layout.WindowInsets).asPaddingValues())`()` Convert a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) to a [PaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues) and uses [LocalDensity](https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/package-summary#LocalDensity()) for DP to pixel conversion.                                                                                                                                       | Cmn |
| [PaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues) | [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`.`[asPaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#(androidx.compose.foundation.layout.WindowInsets).asPaddingValues(androidx.compose.ui.unit.Density))`(density: `[Density](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density)`)` Convert a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) to a [PaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues) and uses [density](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).asPaddingValues(androidx.compose.ui.unit.Density)) for DP to pixel conversion.                | Cmn |
| [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)   | [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`.`[exclude](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#(androidx.compose.foundation.layout.WindowInsets).exclude(androidx.compose.foundation.layout.WindowInsets))`(insets: `[WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`)` Returns the values in this [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that are not also in [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).exclude(androidx.compose.foundation.layout.WindowInsets)).                                                                                                            | Cmn |
| [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)   | [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`.`[only](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#(androidx.compose.foundation.layout.WindowInsets).only(androidx.compose.foundation.layout.WindowInsetsSides))`(sides: `[WindowInsetsSides](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsetsSides)`)` Returns a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that eliminates all dimensions except the ones that are enabled.                                                                                                                                                                                                                                                                                                 | Cmn |
| [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)   | [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`.`[union](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#(androidx.compose.foundation.layout.WindowInsets).union(androidx.compose.foundation.layout.WindowInsets))`(insets: `[WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`)` Returns a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that has the maximum values of this [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) and [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).union(androidx.compose.foundation.layout.WindowInsets)). | Cmn |

## Public functions

### getBottom

Cmn  
Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)  

```
fun getBottom(density: Density): Int
```

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

### getLeft

Cmn  
Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)  

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

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

### getRight

Cmn  
Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)  

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

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

### getTop

Cmn  
Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.2.0)  

```
fun getTop(density: Density): Int
```

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

## Extension functions

### add

Cmn  
Artifact: [androidx.compose.foundation:foundation-layout](https://developer.android.com/jetpack/androidx/releases/compose-foundation)  
[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/layout/WindowInsets.kt+function:add)  

```
fun WindowInsets.add(insets: WindowInsets): WindowInsets
```

Returns a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that has values of this, added to the values of [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).add(androidx.compose.foundation.layout.WindowInsets)). For example, if this has a top of 10 and insets has a top of 5, the returned [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) will have a top of 15.  

### asPaddingValues

Cmn  
Artifact: [androidx.compose.foundation:foundation-layout](https://developer.android.com/jetpack/androidx/releases/compose-foundation)  
[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/layout/WindowInsets.kt+function:asPaddingValues)  

```
@Composable
fun WindowInsets.asPaddingValues(): PaddingValues
```

Convert a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) to a [PaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues) and uses [LocalDensity](https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/package-summary#LocalDensity()) for DP to pixel conversion. [PaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/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](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.ui.Modifier).consumeWindowInsets(androidx.compose.foundation.layout.WindowInsets)) after the padding is applied if insets are to be used further down the hierarchy.  

```kotlin
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.lazy.LazyColumn
import androidx.core.view.WindowCompat

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

### asPaddingValues

Cmn  
Artifact: [androidx.compose.foundation:foundation-layout](https://developer.android.com/jetpack/androidx/releases/compose-foundation)  
[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/layout/WindowInsets.kt+function:asPaddingValues)  

```
fun WindowInsets.asPaddingValues(density: Density): PaddingValues
```

Convert a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) to a [PaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues) and uses [density](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).asPaddingValues(androidx.compose.ui.unit.Density)) for DP to pixel conversion. [PaddingValues](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/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](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.ui.Modifier).consumeWindowInsets(androidx.compose.foundation.layout.WindowInsets)) after the padding is applied if insets are to be used further down the hierarchy.  

```kotlin
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.lazy.LazyColumn
import androidx.core.view.WindowCompat

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

### exclude

Cmn  
Artifact: [androidx.compose.foundation:foundation-layout](https://developer.android.com/jetpack/androidx/releases/compose-foundation)  
[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/layout/WindowInsets.kt+function:exclude)  

```
fun WindowInsets.exclude(insets: WindowInsets): WindowInsets
```

Returns the values in this [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that are not also in [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).exclude(androidx.compose.foundation.layout.WindowInsets)). For example, if this [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) has a [WindowInsets.getTop](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getTop(androidx.compose.ui.unit.Density)) value of `10` and [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).exclude(androidx.compose.foundation.layout.WindowInsets)) has a [WindowInsets.getTop](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getTop(androidx.compose.ui.unit.Density)) value of `8`, the returned [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) will have a [WindowInsets.getTop](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getTop(androidx.compose.ui.unit.Density)) value of `2`.

Negative values are never returned. For example if [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).exclude(androidx.compose.foundation.layout.WindowInsets)) has a [WindowInsets.getTop](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getTop(androidx.compose.ui.unit.Density)) of `10` and this has a [WindowInsets.getTop](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getTop(androidx.compose.ui.unit.Density)) of `0`, the returned [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) will have a [WindowInsets.getTop](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getTop(androidx.compose.ui.unit.Density)) value of `0`.  

### only

Cmn  
Artifact: [androidx.compose.foundation:foundation-layout](https://developer.android.com/jetpack/androidx/releases/compose-foundation)  
[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/layout/WindowInsets.kt+function:only)  

```
fun WindowInsets.only(sides: WindowInsetsSides): WindowInsets
```

Returns a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that eliminates all dimensions except the ones that are enabled. For example, to have a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) at the bottom of the screen, pass [WindowInsetsSides.Bottom](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsetsSides#Bottom()).  

### union

Cmn  
Artifact: [androidx.compose.foundation:foundation-layout](https://developer.android.com/jetpack/androidx/releases/compose-foundation)  
[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/layout/WindowInsets.kt+function:union)  

```
fun WindowInsets.union(insets: WindowInsets): WindowInsets
```

Returns a [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that has the maximum values of this [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) and [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).union(androidx.compose.foundation.layout.WindowInsets)).