xref: /aosp_15_r20/external/accompanist/docs/insets.md (revision fa44fe6ae8e729aa3cfe5c03eedbbf98fb44e2c6)
1# Insets for Jetpack Compose
2
3[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-insets)](https://search.maven.org/search?q=g:com.google.accompanist)
4
5!!! warning
6    **This library is deprecated, with official insets support in androidx.compose.foundation.** The migration guide and original documentation is below.
7
8## Migration
9
10The official `androidx.compose.foundation` insets support is very similar to accompanist/insets, with a few changes.
11
12`androidx.compose.foundation` also does not disable window decor fitting, so you still need to call [`WindowCompat.setDecorFitsSystemWindows(window, false)`](https://developer.android.com/reference/androidx/core/view/WindowCompat#setDecorFitsSystemWindows(android.view.Window,%20boolean)) from your Activity.
13You also still need to set the system bar backgrounds to be transparent, which can be done with our [System UI Controller](../systemuicontroller) library.
14
15If you are using insets for IME support, you also still need to ensure that the activity's `windowSoftInputMode` is set to `adjustResize`:
16
17```xml
18<activity
19      android:name=".MyActivity"
20      android:windowSoftInputMode="adjustResize">
21</activity>
22```
23
24## Migration steps:
25
261. Remove `ProvideWindowInsets` (there is no equivalent in `androidx.compose.foundation`)
271. Remove `ViewWindowInsetObserver` (there is no equivalent in `androidx.compose.foundation`)
281. Replace padding modifiers with `androidx.compose.foundation` equivalents. If using `additionalPadding` or only applying the insets to certain sides, use the corresponding [`WindowInsets.add`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).add(androidx.compose.foundation.layout.WindowInsets)) and [`WindowInsets.only`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).only(androidx.compose.foundation.layout.WindowInsetsSides)) extensions.
291. Replace `rememberInsetsPaddingValues` with the equivalent `WindowInsets.asPaddingValues`.
301. Replace direct calculations from `LocalWindowInsets.current` with calculations on `WindowInsets`.
311. Continue using the non-deprecated [`insets-ui`](#inset-aware-layouts-insets-ui) for now.
32
33For reference, consult the [Migration table](#migration-table) below.
34
35## Inset consumption
36
37The biggest behavioral change between `accompanist/insets` and `androidx.compose.foundation` is in the consumption behavior of padding modifiers.
38
39In `accompanist/insets`, the padding modifiers always padded the full size of the specified inset types, which led to some unintuitive duplicate padding when nesting modifiers.
40
41For example, let’s look at what happens when we have nested boxes, where the outer one has Modifier.systemBarsPadding() applied, and the inner has Modifier.imePadding():
42
43```kotlin
44Box(Modifier.systemBarsPadding()) {
45    Box(Modifier.imePadding()) {
46        // content
47    }
48}
49```
50
51Let’s assume that the bottom system bar padding is `30dp`, to account for the navigation bar padding, and let’s assume that when the IME is visible, the height of the IME is `150dp`.
52
53When the IME is closed, the outer box will apply the bottom `30dp` as padding, and the inner box will apply zero additional padding, since the IME isn’t visible.
54
55When the IME opens, the outer box will continue to apply the bottom `30dp` as the system bar padding, and the inner box will now apply `150dp` bottom padding, since that is the full height of the IME.
56
57This results in a total padding of `180dp` applied to the content, which double pads the bottom navigation bar padding.
58The solutions to this issue were using `derivedWindowInsetsTypeOf`, built-in derived types like `Modifier.navigationBarsWithImePadding()`, or performing calculations manually to apply the remaining padding.
59
60In `androidx.compose.foundation`, when the IME is open, the outer box still apply the bottom `30dp`, but the inner box will only apply the remaining `120dp` needed to have the content be padded a total of `150dp` to match the height of the IME.
61
62This behavior can be influenced further in `androidx.compose.foundation` with [`Modifier.consumedWindowInsets()`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).consumedWindowInsets(androidx.compose.foundation.layout.WindowInsets))
63
64As a result, the equivalent of `Modifier.navigationBarsWithImePadding()` is simply `Modifier.navigationBarsPadding().imePadding()`.
65
66## Migration table:
67
68| accompanist/insets                                                                                                                | androidx.compose.foundation                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
69|-----------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
70| `ProvideWindowInsets`                                                                                                             | (remove)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
71| `Modifier.systemBarsPadding()`                                                                                                    | [`Modifier.systemBarsPadding()`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).systemBarsPadding())                                                                                                                                                                                                                                                                                                                                        |
72| `Modifier.systemBarsPadding(bottom = false)`                                                                                      | [`Modifier.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top))`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.ui.Modifier).windowInsetsPadding(androidx.compose.foundation.layout.WindowInsets))                                                                                                                                                                             |
73| `Modifier.statusBarsPadding()`                                                                                                    | [`Modifier.statusBarsPadding()`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).statusBarsPadding())                                                                                                                                                                                                                                                                                                                                        |
74| `Modifier.navigationBarsPadding()`                                                                                                | [`Modifier.navigationBarsPadding()`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).navigationBarsPadding())                                                                                                                                                                                                                                                                                                                                |
75| `Modifier.imePadding()`                                                                                                           | [`Modifier.imePadding()`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).imePadding())                                                                                                                                                                                                                                                                                                                                                      |
76| `Modifier.cutoutPadding()`                                                                                                        | [`Modifier.displayCutoutPadding()`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).displayCutoutPadding())                                                                                                                                                                                                                                                                                                                                  |
77| `Modifier.navigationBarsWithImePadding()`                                                                                         | [`Modifier.navigationBarsPadding().imePadding()`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).imePadding())                                                                                                                                                                                                                                                                                                                              |
78| `Modifier.statusBarsHeight()`                                                                                                     | [`Modifier.windowInsetsTopHeight(WindowInsets.statusBars)`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).windowInsetsTopHeight(androidx.compose.foundation.layout.WindowInsets))                                                                                                                                                                                                                                                          |
79| `Modifier.navigationBarsHeight()`                                                                                                 | [`Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars)`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).windowInsetsBottomHeight(androidx.compose.foundation.layout.WindowInsets))                                                                                                                                                                                                                                                |
80| `Modifier.navigationBarsWidth()`                                                                                                  | [`Modifier.windowInsetsStartWidth(WindowInsets.navigationBars)`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).windowInsetsStartWidth(androidx.compose.foundation.layout.WindowInsets)) / [`Modifier.windowInsetsEndWidth(WindowInsets.navigationBars)`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).windowInsetsEndWidth(androidx.compose.foundation.layout.WindowInsets)) |
81| `rememberInsetsPaddingValues(insets = LocalWindowInsets.current.statusBars, applyStart = true, applyTop = true, applyEnd = true)` | [`WindowInsets.statusBars.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top).asPaddingValues()`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).asPaddingValues())                                                                                                                                                                                                                         |
82| `derivedWindowInsetsTypeOf`                                                                                                       | [`WindowInsets.union(windowInsets: WindowInsets)`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets).union(androidx.compose.foundation.layout.WindowInsets))                                                                                                                                                                                                                                          |
83| `LocalWindowInsets.current.navigationBars`                                                                                        | [`WindowInsets.navigationBars`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets.Companion).navigationBars())                                                                                                                                                                                                                                                                                         |
84| `LocalWindowInsets.current.statusBars`                                                                                            | [`WindowInsets.statusBars`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets.Companion).statusBars())                                                                                                                                                                                                                                                                                                 |
85| `LocalWindowInsets.current.ime`                                                                                                   | [`WindowInsets.ime`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets.Companion).ime())                                                                                                                                                                                                                                                                                                               |
86| `LocalWindowInsets.current.systemGestures`                                                                                        | [`WindowInsets.systemGestures`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets.Companion).systemGestures())                                                                                                                                                                                                                                                                                         |
87| `LocalWindowInsets.current.systemBars`                                                                                            | [`WindowInsets.systemBars`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets.Companion).systemBars())                                                                                                                                                                                                                                                                                                 |
88| `LocalWindowInsets.current.displayCutout`                                                                                         | [`WindowInsets.displayCutout`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets.Companion).displayCutout())                                                                                                                                                                                                                                                                                           |
89| `LocalWindowInsets.current.ime.bottom`                                                                                            | [`WindowInsets.ime.getBottom(LocalDensity.current)`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/WindowInsets#getBottom(androidx.compose.ui.unit.Density))                                                                                                                                                                                                                                                                                                        |
90| `WindowInsets.Type.isVisible`                                                                                                     | [`WindowInsets.isImeVisible`](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#(androidx.compose.foundation.layout.WindowInsets.Companion).isImeVisible()), etc.                                                                                                                                                                                                                                                                                       |
91| `WindowInsets.Type.animationInProgress`                                                                                           | [Bug: 217770337](https://issuetracker.google.com/issues/217770337)                                                                                                                                                                                                                                                                                                                                                                                                                                      |
92| `WindowInsets.Type.animationFraction`                                                                                             | [Bug: 217770337](https://issuetracker.google.com/issues/217770337)                                                                                                                                                                                                                                                                                                                                                                                                                                      |
93| `WindowInsets.Type.layoutInsets`                                                                                                  | [Bug: 217770337](https://issuetracker.google.com/issues/217770337)                                                                                                                                                                                                                                                                                                                                                                                                                                      |
94| `WindowInsets.Type.animatedInsets`                                                                                                | [Bug: 217770337](https://issuetracker.google.com/issues/217770337)                                                                                                                                                                                                                                                                                                                                                                                                                                      |
95| `rememberImeNestedScrollConnection()`                                                                                             | [`Modifier.imeNestedScroll()`](https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).imeNestedScroll())                                                                                                                                                                                                                                                                                                                                            |
96
97## Original docs
98
99Insets for Jetpack Compose takes a lot of the ideas which drove [Insetter][insetter-view] for views, and applies them for use in composables.
100
101## Usage
102To setup Insets in your composables, you need to call the `ProvideWindowInsets` function and
103wrap your content. This would typically be done near the top level of your composable hierarchy:
104
105``` kotlin
106setContent {
107  MaterialTheme {
108    ProvideWindowInsets {
109      // your content
110    }
111  }
112}
113```
114
115!!! note
116    **This library does not disable window decor fitting.** For your view hierarchy to able to receive insets, you need to make sure to call: [`WindowCompat.setDecorFitsSystemWindows(window, false)`](https://developer.android.com/reference/androidx/core/view/WindowCompat#setDecorFitsSystemWindows(android.view.Window,%20boolean)) from your Activity. You also need to set the system bar backgrounds to be transparent, which can be done with our [System UI Controller](../systemuicontroller) library.
117
118`ProvideWindowInsets` allows the library to set an [`OnApplyWindowInsetsListener`][insetslistener] on your content's host view. That listener is used to update the value of a composition local bundled in this library: `LocalWindowInsets`.
119
120`LocalWindowInsets` holds an instance of `WindowInsets` which contains the value of various [WindowInsets][insets] [types][insettypes]. You can use the values manually like so:
121
122``` kotlin
123@Composable
124fun ImeAvoidingBox() {
125    val insets = LocalWindowInsets.current
126
127    val imeBottom = with(LocalDensity.current) { insets.ime.bottom.toDp() }
128    Box(Modifier.padding(bottom = imeBottom))
129}
130```
131
132...but we also provide some easy-to-use [Modifier][modifier]s.
133
134### Modifiers
135
136We provide two types of modifiers for easy handling of insets: padding and size.
137
138#### Padding modifiers
139The padding modifiers allow you to apply padding to a composable which matches a specific type of inset. Currently we provide:
140
141- [`Modifier.statusBarsPadding()`](../api/insets/com.google.accompanist.insets/status-bars-padding.html)
142- [`Modifier.navigationBarsPadding()`](../api/insets/com.google.accompanist.insets/navigation-bars-padding.html)
143- [`Modifier.systemBarsPadding()`](../api/insets/com.google.accompanist.insets/system-bars-padding.html)
144- [`Modifier.imePadding()`](../api/insets/com.google.accompanist.insets/ime-padding.html)
145- [`Modifier.navigationBarsWithImePadding()`](../api/insets/com.google.accompanist.insets/navigation-bars-with-ime-padding.html)
146- [`Modifier.cutoutPadding()`](../api/insets/com.google.accompanist.insets/cutout-padding.html)
147
148These are commonly used to move composables out from under the system bars. The common example would be a [`FloatingActionButton`][fab]:
149
150``` kotlin
151FloatingActionButton(
152    onClick = { /* TODO */ },
153    modifier = Modifier
154        .align(Alignment.BottomEnd)
155        .padding(16.dp) // normal 16dp of padding for FABs
156        .navigationBarsPadding() // Move it out from under the nav bar
157) {
158    Icon(imageVector = Icons.Default.Add, contentDescription = null)
159}
160```
161
162#### Size modifiers
163The size modifiers allow you to match the size of a composable to a specific type of inset. Currently we provide:
164
165- [`Modifier.statusBarsHeight()`](../api/insets/com.google.accompanist.insets/status-bars-height.html)
166- [`Modifier.navigationBarsHeight()`](../api/insets/com.google.accompanist.insets/navigation-bars-height.html)
167- [`Modifier.navigationBarsWidth()`](../api/insets/com.google.accompanist.insets/navigation-bars-width.html)
168
169These are commonly used to allow composables behind the system bars, to provide background protection, or similar:
170
171``` kotlin
172Spacer(
173    Modifier
174        .background(Color.Black.copy(alpha = 0.7f))
175        .statusBarsHeight() // Match the height of the status bar
176        .fillMaxWidth()
177)
178```
179
180### PaddingValues
181Compose also provides the concept of [`PaddingValues`][paddingvalues], a data class which contains the padding values to be applied on all dimensions (similar to a rect). This is commonly used with container composables, such as [`LazyColumn`][lazycolumn], to set the content padding.
182
183You may want to use inset values for content padding, so this library provides the [`rememberInsetsPaddingValues()`](..//api/insets/com.google.accompanist.insets/remember-insets-padding-values.html) extension function to convert between `Insets` and [`PaddingValues`][paddingvalues]. Here's an example of using the system bars insets:
184
185``` kotlin
186LazyColumn(
187    contentPadding = rememberInsetsPaddingValues(
188        insets = LocalWindowInsets.current.systemBars,
189        applyTop = true,
190        applyBottom = true,
191    )
192) {
193    // content
194}
195```
196
197For a more complex example, see the [`EdgeToEdgeLazyColumn`](https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/insets/EdgeToEdgeLazyColumn.kt) example:
198
199<a href="images/edge-to-edge-list.jpg">
200<img src="images/edge-to-edge-list.jpg" width=300>
201</a>
202
203## Inset-aware layouts (`insets-ui`)
204
205!!! warning
206    **This library is deprecated, with [official support](https://android-review.googlesource.com/c/platform/frameworks/support/+/2667875) in androidx.compose.material.** The original documentation is below.
207
208Unfortunately, most of Compose Material's layouts do not support the use of content padding, which means that the following code probably doesn't produce the effect you want:
209
210``` kotlin
211// �� This likely doesn't do what you want
212TopAppBar(
213    // content
214    modifier = Modifier.statusBarsPadding()
215)
216```
217
218To workaround this, we provide the `insets-ui` companion library which contains versions of commonly used layouts, with the addition of a `contentPadding` parameter. The example below is using our [`TopAppBar`](../api/insets-ui/com.google.accompanist.insets.ui/-top-app-bar.html) layout, providing the status bar insets to use as content padding:
219
220``` kotlin
221import com.google.accompanist.insets.ui.TopAppBar
222
223TopAppBar(
224    contentPadding = rememberInsetsPaddingValues(
225        insets = LocalWindowInsets.current.statusBars,
226        applyStart = true,
227        applyTop = true,
228        applyEnd = true,
229    )
230) {
231    // content
232}
233```
234
235The library also provides a modified copy of Compose Material's [`Scaffold`](https://developer.android.com/reference/kotlin/androidx/compose/material/package-summary#Scaffold(androidx.compose.ui.Modifier,androidx.compose.material.ScaffoldState,kotlin.Function0,kotlin.Function0,kotlin.Function1,kotlin.Function0,androidx.compose.material.FabPosition,kotlin.Boolean,kotlin.Function1,kotlin.Boolean,androidx.compose.ui.graphics.Shape,androidx.compose.ui.unit.Dp,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,kotlin.Function1)) which better supports edge-to-edge layouts, by drawing the top and bottom bars over the content.
236
237``` kotlin
238Scaffold(
239    topBar = {
240        // We use TopAppBar from accompanist-insets-ui which allows us to provide
241        // content padding matching the system bars insets.
242        TopAppBar(
243            title = { Text(stringResource(R.string.insets_title_list)) },
244            backgroundColor = MaterialTheme.colors.surface.copy(alpha = 0.9f),
245            contentPadding = rememberInsetsPaddingValues(
246                LocalWindowInsets.current.statusBars,
247                applyBottom = false,
248            ),
249        )
250    },
251    bottomBar = {
252        // We add a spacer as a bottom bar, which is the same height as
253        // the navigation bar
254        Spacer(Modifier.navigationBarsHeight().fillMaxWidth())
255    },
256) { contentPadding ->
257    // We apply the contentPadding passed to us from the Scaffold
258    Box(Modifier.padding(contentPadding)) {
259        // content
260    }
261}
262```
263
264See the [API docs](../api/insets-ui/com.google.accompanist.insets.ui/) for a list of the other layouts provided in the library.
265
266### Animated Insets support
267
268=== "Info"
269
270    ![](images/ime-insets.gif){: align=right loading=lazy }
271
272    The library now has experimental support for [`WindowInsetsAnimations`](https://developer.android.com/reference/android/view/WindowInsetsAnimation), allowing your content is react to inset animations, such as the on screen-keyboard (IME) being animated on/off screen. The `imePadding()` and `navigationBarsWithImePadding()` modifiers are available especially for this use-case.
273
274    This functionality works wherever [WindowInsetsAnimationCompat](https://developer.android.com/reference/androidx/core/view/WindowInsetsAnimationCompat) works, which at the time or writing is on devices running API 21+.
275
276    To enable animated insets support, you need need to new `ProvideWindowInsets` overload, and set `windowInsetsAnimationsEnabled = true`.
277
278=== "Usage"
279
280    ``` kotlin
281    ProvideWindowInsets(windowInsetsAnimationsEnabled = true) {
282        // content
283    }
284    ```
285
286    You can then use the new `navigationBarsWithImePadding()` modifier like so:
287
288    ``` kotlin
289    OutlinedTextField(
290        // other params,
291        modifier = Modifier.navigationBarsWithImePadding()
292    )
293    ```
294
295    See the [ImeAnimationSample](https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/insets/ImeAnimationSample.kt) for a working example.
296
297### IME animations
298If you're using the animation insets support for IME/keyboard animations, you also need to ensure that the activity's `windowSoftInputMode` is set to `adjustResize`:
299
300``` xml
301<activity
302      android:name=".MyActivity"
303      android:windowSoftInputMode="adjustResize">
304</activity>
305```
306
307The default value of `windowSoftInputMode` _should_ work, but Compose does not currently set the flags necessary (see [here](https://issuetracker.google.com/154101484)).
308
309## �� Experimental
310
311The features below are experimental, and require developers to [opt-in](https://kotlinlang.org/docs/reference/opt-in-requirements.html).
312
313### Controlling the IME (on-screen keyboard)
314
315=== "Info"
316
317    ![](images/ime-scroll.gif){: loading=lazy align=right }
318
319    This library also has support for controlling the IME from scroll gestures, allowing your scrollable components to pull/push the IME on/off screen. This is achieved through the built-in [`NestedScrollConnection`](https://developer.android.com/reference/kotlin/androidx/compose/ui/gesture/nestedscroll/NestedScrollConnection) implementation returned by [`rememberImeNestedScrollConnection()`](../api/insets/com.google.accompanist.insets/remember-ime-nested-scroll-connection.html).
320
321    This functionality only works when running on devices with API 30+.
322
323=== "Usage"
324
325    ``` kotlin
326    // Here we're using a scrollable Column, but it also works with LazyColumn, etc.
327    Column(
328        // We use the nestedScroll modifier, passing in the
329        // the connection from rememberImeNestedScrollConnection()
330        modifier = Modifier
331            .nestedScroll(connection = rememberImeNestedScrollConnection())
332            .verticalScroll(state = rememberScrollState())
333    ) {
334        // list content
335    }
336    ```
337
338    See the [ImeAnimationSample](https://github.com/google/accompanist/blob/main/sample/src/main/java/com/google/accompanist/sample/insets/ImeAnimationSample.kt) for a working example.
339
340
341## Download
342
343[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-insets)](https://search.maven.org/search?q=g:com.google.accompanist)
344
345```groovy
346repositories {
347    mavenCentral()
348}
349
350dependencies {
351    implementation "com.google.accompanist:accompanist-insets:<version>"
352    // If using insets-ui
353    implementation "com.google.accompanist:accompanist-insets-ui:<version>"
354}
355```
356
357Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. These are updated on every commit.
358
359## Something not working?
360
361If you find that something isn't working correctly, here's a checklist to try:
362
363- Check that you've called [`WindowCompat.setDecorFitsSystemWindows(window, false)`](https://developer.android.com/reference/androidx/core/view/WindowCompat#setDecorFitsSystemWindows(android.view.Window,%20boolean)) in your Activity. Unless you do that, the window decor will consume the insets, and they will not be dispatched to your content.
364- If it's something related to the keyboard, check that the Activity's `windowSoftInputMode` is set to [`adjustResize`](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#SOFT_INPUT_ADJUST_RESIZE). Without that, IME visibility changes will not be sent as inset changes.
365- Similarly, if you're setting [`android:windowFullscreen`](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_FULLSCREEN) to `true` (or using a `.Fullscreen` theme), be aware that `adjustResize` will not work. Please see the [documentation](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_FULLSCREEN) for an alternative.
366- If you're using `ProvideWindowInsets` (or `ViewWindowInsetObserver`) in multiple layers of your view hierarchy (i.e. in the activity, _and_ in a fragment), you need to turn off consuming of insets. By default `ProvideWindowInsets` and `ViewWindowInsetObserver` will completely consume any insets passed to it. In the previous example, this means that the activity content will get the insets, but the fragment won't. To disable consuming, pass `consumeWindowInsets = false` to `ProvideWindowInsets` or `ViewWindowInsetObserver.start()`.
367
368[compose]: https://developer.android.com/jetpack/compose
369[snap]: https://oss.sonatype.org/content/repositories/snapshots/com/google/accompanist/accompanist-insets/
370[insetter-view]: https://github.com/chrisbanes/insetter
371[insets]: https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat
372[insettypes]: https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat.Type
373[insetslistener]: https://developer.android.com/reference/kotlin/androidx/core/view/OnApplyWindowInsetsListener
374[modifier]: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier
375[paddingvalues]: https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/PaddingValues
376[lazycolumn]: https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/package-summary#lazycolumn
377[fab]: https://developer.android.com/reference/kotlin/androidx/compose/material/package-summary#floatingactionbutton
378[api-type]: ../api/insets/com.google.accompanist.insets/-window-insets/-type/
379