# MutableWindowInsets

# MutableWindowInsets

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.MutableWindowInsets)  
Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.3.0)
Common/AllAndroid/JVM
  - Cmn  

  ```
  @ExperimentalLayoutApi
  class MutableWindowInsets : WindowInsets
  ```

*** ** * ** ***

A [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) whose values can change without changing the instance. This is useful to avoid recomposition when [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) can change.  

```kotlin
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.MutableWindowInsets
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.exclude
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.onConsumedWindowInsetsChanged
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContent
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat

class SampleActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false)
        super.onCreate(savedInstanceState)
        setContent {
            val remainingInsets = remember { MutableWindowInsets() }
            val safeContent = WindowInsets.safeContent
            Box(
                Modifier.navigationBarsPadding().onConsumedWindowInsetsChanged {
                    consumedWindowInsets ->
                    remainingInsets.insets = safeContent.exclude(consumedWindowInsets)
                }
            ) {
                // padding can be used without recomposition when insets change.
                val padding = remainingInsets.asPaddingValues()
                Box(Modifier.padding(padding))
            }
        }
    }
}
```

Note: This API as experimental since it doesn't enforce the right consumption patterns.

## Summary

|                                                                                                                                                       ### Public constructors                                                                                                                                                        |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [MutableWindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#MutableWindowInsets(androidx.compose.foundation.layout.WindowInsets))`(initialInsets: `[WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets)`)` | Cmn |

|                                ### Public functions                                |
|------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `open `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getBottom](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#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 |
| `open `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getLeft](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#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 |
| `open `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getRight](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#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 |
| `open `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getTop](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#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 |

|                                             ### Public properties                                              |
|----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) | [insets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#insets()) The [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that are used for [left](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#getLeft(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection)), [top](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#getTop(androidx.compose.ui.unit.Density)), [right](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#getRight(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection)), and [bottom](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#getBottom(androidx.compose.ui.unit.Density)) values. | Cmn |

## Public constructors

### MutableWindowInsets

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

```
MutableWindowInsets(
    initialInsets: WindowInsets = WindowInsets(0, 0, 0, 0)
)
```

## Public functions

### getBottom

Cmn  

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

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

### getLeft

Cmn  

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

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

### getRight

Cmn  

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

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

### getTop

Cmn  

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

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

## Public properties

### insets

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

```
var insets: WindowInsets
```

The [WindowInsets](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets) that are used for [left](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#getLeft(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection)), [top](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#getTop(androidx.compose.ui.unit.Density)), [right](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#getRight(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection)), and [bottom](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/MutableWindowInsets#getBottom(androidx.compose.ui.unit.Density)) values.