Skip to content

Commit

Permalink
Render below status bar in portrait on devices with a display cutout
Browse files Browse the repository at this point in the history
  • Loading branch information
soupslurpr committed Dec 18, 2023
1 parent e16f793 commit 49279ea
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions app/src/main/java/app/grapheneos/pdfviewer/ktx/View.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
package app.grapheneos.pdfviewer.ktx

import android.content.res.Configuration
import android.os.Build
import android.view.View
import android.view.Window
import android.view.WindowInsetsController
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat

private val systemBars = WindowInsetsCompat.Type.statusBars()

fun View.hideSystemUi(window: Window) {
val controller = WindowCompat.getInsetsController(window, this)
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
controller.hide(systemBars)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val controller = window.insetsController
controller?.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
if (window.decorView.rootWindowInsets.displayCutout == null) {
controller?.hide(systemBars)
} else if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
controller?.hide(systemBars)
}
} else {
val controller = WindowCompat.getInsetsController(window, this)
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) && (window.decorView.rootWindowInsets.displayCutout == null)) {
controller.hide(systemBars)
} else if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
controller.hide(systemBars)
}
}
}

fun View.showSystemUi(window: Window) {
WindowCompat.getInsetsController(window, this).show(systemBars)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val controller = window.insetsController
controller?.show(systemBars)
} else {
val controller = WindowCompat.getInsetsController(window, this)
controller.show(systemBars)
}
}

0 comments on commit 49279ea

Please sign in to comment.