WindowInsets Handling & Keyboard Animations

Jul 20 2021 · Kotlin 1.5.10, Android 11, Android Studio 4.1.3 and Android Studio Arctic Fox Canary 12

Part 2: Keyboard Handling in Jetpack Compose

08. Adjust the System Windows

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 07. Read the Keyboard Visibility Next episode: 09. Animate the Keyboard & Surrounding Views

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 08. Adjust the System Windows

Prerequisites: Jetpack Compose requires that you use the Canary build of Android Studio. You can download it from:

Transcript: 08. Adjust the System Windows

In this episode you’ll learn how to use the: System UI Controller, LazyColumn, Modifiers, ProvideWindowInsets, API’s.

Lists in Compose can be vertical through the use of LazyColumn, like this one. Or you can use instead LazyRow to create a horizontal one. Their attributes can be manipulated through the use of Modifiers that allow to define parameters like: width, height, background color, etc.

In this episode you’ll see how to adjust the system windows using Jetpack Compose.

To adjust the System Windows with Compose, you’ll use CompositionLocalProvider.

You’ll need the accompanist system ui controller library that’s already added to the app build.gradle file:

implementation("com.google.accompanist:accompanist-systemuicontroller:0.11.1")

Go over Chat.kt file and see the Chat function. Here, is where the screen components are being added:

LazyColumn - Contains all the notes that are going to be added

TextField - Corresponds to the input field on which the user can add new notes.

To restrain the view into its boundaries, you’ll need to use padding. Starting with the status bar, let’s move the list down. The LazyColumn as an argument called contentPadding. Add the status bar padding to pull it down:

contentPadding = rememberInsetsPaddingValues(
  LocalWindowInsets.current.statusBars,
  applyBottom = false,
),

Now to push the input field to be above the navigation bar, it’s necessary to update the Row composable that contains the TextField. On the Modifier attribute, just call:

.navigationBarsWithImePadding()

To automatically readjust the Row’s content. Finally, open MainScreen.kt file and update the TopAppBar Modifier to readjust it to be under the status bar. For that, add to the Modifier:

modifier = Modifier
             .statusBarsPadding()
             .navigationBarsPadding(bottom = false),

One last change, open MainFragment.kt file and inside RWTheme, which corresponds to where the activity theme is being set, add:

ProvideWindowInsets(windowInsetsAnimationsEnabled = true) {

  MainScreen()
}

That’s it! Yes, it’s really simple to adjust the app to the system windows using Jetpack Compose. Let’s compile and run the app to try out this feature. Now that the app is open, don’t forget to add the episode name to the list: 08: Adjust the System Windows

See you in the next episode!