auto hide android navbar (#133)

* auto hide android navbar

* auto hide android navbar
This commit is contained in:
aayush262 2024-01-16 00:25:21 +05:30 committed by GitHub
parent bd6197031a
commit 61150066bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 16 deletions

View file

@ -157,11 +157,22 @@ fun initActivity(a: Activity) {
}
}
a.hideStatusBar()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && statusBarHeight == 0 && a.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
window.decorView.rootWindowInsets?.displayCutout?.apply {
if (boundingRects.size > 0) {
statusBarHeight = min(boundingRects[0].width(), boundingRects[0].height())
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
statusBarHeight == 0 &&
a.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
) {
window.setDecorFitsSystemWindows(false)
window.decorView.setOnApplyWindowInsetsListener { _, insets ->
statusBarHeight = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top
navBarHeight = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
insets
}
window.insetsController?.let { controller ->
controller.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
controller.hide(WindowInsetsCompat.Type.navigationBars())
}
}
} else