Commit 6d8e7ad4 authored by mcarare's avatar mcarare Committed by mergify[bot]
Browse files

For #9554: Use WindowInsetsControllerCompat to avoid null controllers.

parent e3ca7638
......@@ -8,7 +8,6 @@ import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.view.Window
import androidx.annotation.ColorInt
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsControllerCompat
import mozilla.components.support.utils.ColorUtils.isDark
......@@ -17,7 +16,7 @@ import mozilla.components.support.utils.ColorUtils.isDark
* If the color is light enough, a light status bar with dark icons will be used.
*/
fun Window.setStatusBarTheme(@ColorInt color: Int) {
getWindowInsetsController()?.isAppearanceLightStatusBars =
getWindowInsetsController().isAppearanceLightStatusBars =
isDark(color)
statusBarColor = color
}
......@@ -27,7 +26,7 @@ fun Window.setStatusBarTheme(@ColorInt color: Int) {
* If the color is light enough, a light navigation bar with dark icons will be used.
*/
fun Window.setNavigationBarTheme(@ColorInt color: Int) {
getWindowInsetsController()?.isAppearanceLightNavigationBars =
getWindowInsetsController().isAppearanceLightNavigationBars =
isDark(color)
if (SDK_INT >= Build.VERSION_CODES.P) {
......@@ -39,6 +38,6 @@ fun Window.setNavigationBarTheme(@ColorInt color: Int) {
/**
* Retrieves a {@link WindowInsetsControllerCompat} for the top-level window decor view.
*/
fun Window.getWindowInsetsController(): WindowInsetsControllerCompat? {
return ViewCompat.getWindowInsetsController(this.decorView)
fun Window.getWindowInsetsController(): WindowInsetsControllerCompat {
return WindowInsetsControllerCompat(this, this.decorView)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment