Android-components: Fix Activity.enterToImmersiveMode() deprecation in Android 11

Created on 25 Sep 2020  路  5Comments  路  Source: mozilla-mobile/android-components

<ktx> 11

All 5 comments

I'd love to solve this issue, but there is no AndroidX version of this yet, this would require a SDK_INT check...

The result would look something like this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.insetsController?.apply {
        systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE
        hide(WindowInsets.Type.systemBars())
    }
} else {
    window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_FULLSCREEN
        or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
}

If it is acceptable, I can solve this :)

I'd love to solve this issue, but there is no AndroidX version of this yet, this would require a SDK_INT check...

The result would look something like this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.insetsController?.apply {
        systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE
        hide(WindowInsets.Type.systemBars())
    }
} else {
    window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_FULLSCREEN
        or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
}

If it is acceptable, I can solve this :)

馃憢
@ForceTower sure you could assign it yourself :), feel free to open a draft PR to get early feedback, this video from https://youtu.be/acC7SR1EXsI?t=161 the Android YouTube channel contains some good tips :)

Thanks, I created a draft pull request here: https://github.com/mozilla-mobile/android-components/pull/8577

@Amejia481, @ForceTower If there are more deprecations in the same extensions file I think maybe they should be handled in this issue as well. It will make tracking of all issues easier.

Currently the core-ktx version 1.5.0, which has the WindowCompat API, is still in beta.
Once it is reaches stable I'll update the PR using the new API and remove deprecated calls.

Was this page helpful?
0 / 5 - 0 ratings