Handling The New Gesture Navigation
@esafirm
GESTURE NAVIGATION
WHY?
Gesture Navigation
SO, WHAT NEEDS TO BE DONE?
Let’s have a checklist!
Edge-to-Edge
1
2
Set themes to support edge-to-edge
Request to be laid out full screen
Set the Theme
<style name="AppTheme" parent="...">
<item name="android:navigationBarColor">@color/transparent</item>
<item name="android:statusBarColor">@color/transparent</item>
</style>
Request for Fullscreen
view.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
// draw behind status bar
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
// draw behind navigation bar
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
Request for Fullscreen
view.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
// draw behind status bar
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
// draw behind navigation bar
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
Request for Fullscreen
<androidx.coordinatorlayout.widget.CoordinatorLayout
...
android:fitsSystemWindows="true">
Request for Fullscreen
<androidx.coordinatorlayout.widget.CoordinatorLayout
...
android:fitsSystemWindows="true">
setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
)
Let’s have a checklist!
INSETS
What are insets?
Insets
Window Insets
Gesture Insets
Mandatory Gesture Insets
Let’s apply the Inset!
ViewCompat.setOnApplyWindowInsetsListener(fab) { _, insets ->
fab.updateLayoutParams<MarginLayoutParams> {
updateMargins(bottom = bottomMargin + insets.systemWindowInsetBottom)
}
insets.consumeSystemWindowInsets()
}
Let’s have a checklist!
For complete flow chart click here
View Requires Drag /
Swipe
View is mostly/full laid out inside gesture area
View bounds overlaps any mandatory area?
No gesture conflict to handle
Use the gesture exclusion API
Move views out of gesture area
No
Yes
No
Yes
Yes
No
Example: full width ViewPager
Gesture Exclusion API
slideButton.doOnPreDraw {
ViewCompat.setSystemGestureExclusionRects(it, listOf(
Rect(0, 0, it.right, it.bottom)
))
}
Gesture Exclusion API
// SlideButton.kt
override fun onLayout(,,,) {
// Set the exclusion rects
ViewCompat.setSystemGestureExclusionRects(this, exclusionRects)
}
Gesture Exclusion API
// SlideButton.kt
override fun onDraw(,,,) {
// Set the exclusion rects
ViewCompat.setSystemGestureExclusionRects(this, exclusionRects)
}
Apps can only opt out 200dp of each edges
If apps opt out of more, only the bottom 200dp will be overridden for the app
IMMERSIVE MODE
Let’s have a checklist!
🎉🥳🎉
REFERENCES
THANK YOU