Skip to content

Commit e635c25

Browse files
committed
Set nonexistent status bar to the correct color for day/night mode.
1 parent e1f7ff9 commit e635c25

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

simplified-ui-screen/src/main/java/org/nypl/simplified/ui/screen/ScreenEdgeToEdgeFix.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.nypl.simplified.ui.screen
22

3+
import android.app.Activity
4+
import android.content.res.Configuration
35
import android.os.Build
46
import android.view.View
57
import androidx.core.view.ViewCompat
@@ -32,6 +34,33 @@ object ScreenEdgeToEdgeFix {
3234
view.setPadding(padLeft, padTop, padRight, padBottom)
3335
insets
3436
}
37+
38+
/*
39+
* Google want to pretend that they don't have a status bar, whilst also clearly having
40+
* status bar icons. To facilitate this delusion, we have to set the status bar (that we
41+
* don't have) to light or dark depending on the day/night mode. This is necessary so that
42+
* we don't end up with black icons on a black background, and so on.
43+
*/
44+
45+
val configuration =
46+
rootView.resources.configuration
47+
val context =
48+
rootView.context
49+
50+
if (context is Activity) {
51+
val isNightMode =
52+
(configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
53+
val decor =
54+
context.window.decorView
55+
56+
if (isNightMode) {
57+
decor.systemUiVisibility =
58+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
59+
} else {
60+
decor.systemUiVisibility =
61+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
62+
}
63+
}
3564
}
3665
}
3766
}

0 commit comments

Comments
 (0)