SPEAKER: With gesture navigation,
apps can make fuller use of the display
to create a more immersive user experience,
and are strongly recommended to do so.
In this DevByte, I'll show you how
insets can help you ensure that your immersive user
experience is usable across devices in the ecosystem.
Before watching, please check out
the previous DevBytes that cover how you can render your app
edge to edge.
You can find the links in the notes below.
Once you go edge to edge by rendering your app from top
to bottom, you may encounter some conflicts
with both gesture nav and three button mode.
Both navigation modes coexist in Android 10,
and users decide which navigation mode to use.
For example, here, the app controls
are hidden under the Navigation bar,
making them hard to access.
This might not be super obvious with the gesture navigation
bar.
But it's the inverse with the three button navigation bar.
This is where window insets come to the rescue.
Insets tell you where the system UI
appears on top of your content.
They also tell you the screen regions
where system gestures take priority over in-app gestures.
Insets are represented by the WindowInsets class.
And window insets compact in AndroidX.
No matter what your minimum SDK version is,
we strongly recommended you to use WindowInsetsCompat
from Jetpack to have consistent behavior across all API levels.
Before we focus on the new gesture insets,
let's do a quick recap of the system insets.
System window insets tell you where the system UI is
being displayed over your app.
These insets are dispatched to the view hierarchy
whenever some part of the system UI,
like the Status bar, Navigation bar, or on-screen keyboard,
is displayed above your app.
You can use system insets to move your controls away
from the system bars.
To do that, add an only apply window insets listener
to your view, and include the corresponding inset value
to the viewer's padding or margin.
In this case, we want to include the bottom inset,
since we want to move away from the navigation bar.
And now switching tracks to Android 10.
The Android 10 release has two new inset API
that returns the regions where system gestures are prioritized
over in app gestures.
These new insets are called gesture insights
and mandatory gesture insights.
Gesture insights return both the home gesture area at the bottom
and the back gesture areas on the right
and left edges of the screen.
Any in-app swipe controls in these regions
can be overridden by the system.
If you have swipe-based controls near the right
or left edges of the screen, users
may accidentally trigger the back gesture instead.
If you cannot move your controls away from the edges,
you can use the gesture exclusion reg API to partially
disable system back gesture around your UI controls.
But be very careful.
Users expect to go back when they
swipe from right or left edges.
Creating a large and unnecessary gesture exclusion zone
introduces inconsistent behavior with the system and other apps.
This is why you should use the gesture exclusion
API sparingly.
To ensure overall consistency, there
is a limit of 200 dips for the gesture exclusion reg
API on each edge.
If you request more than 200 dips in height,
the system will only respect 200 dips
from bottom on either sides.
Moving onto mandatory gesture insets.
These insets are a subset of the system gesture insets.
They tell you the areas of the screen
where the behavior of the system gesture
will always take priority over in-app gestures.
Mandatory gesture zones can never
be excluded by apps, although the system has
some automatic allowances for text selection reg handles.
Note that with Android 10, the home gesture region
is reflected as a mandatory system gesture
to ensure that the user is always able to exit the app
while in gesture nav.
If your app has swipe controls in the mandatory gesture insets
region the system will capture user gestures,
and your app may never receive these gestures.
You should use mandatory insets to move your content away
from the mandatory gesture region.
If your app uses immersive mode, make
sure to watch the DevByte about gesture navigation
with immersive mode, which is, again,
linked in the notes below.
Also, we are working on making handling insets easier.
Keep an eye out on the AndroidX release pages
for more information.
If you want to learn more about the insets and other inset
API, which are not covered here, check out
the blog post series from Chris Baines,
which is also linked below.
If you liked the video, please hit the Like button,
and subscribe to the channel for more of some Android videos.
Thanks for watching!
Don't forget to inset your app controls, and swipe happily.
[MUSIC PLAYING]