@@ -14,8 +14,8 @@ import dev.hotwire.turbo.nav.TurboNavDestination
14
14
import dev.hotwire.turbo.util.animateColorTo
15
15
16
16
internal class TurboWindowThemeObserver (val destination : TurboNavDestination ) : LifecycleObserver {
17
- private val window: Window
18
- get() = destination.fragment.requireActivity() .window
17
+ private val window: Window ?
18
+ get() = destination.fragment.activity? .window
19
19
20
20
@OnLifecycleEvent(Lifecycle .Event .ON_START )
21
21
fun updateSystemBarColors () {
@@ -39,8 +39,8 @@ internal class TurboWindowThemeObserver(val destination: TurboNavDestination) :
39
39
val statusBarColor = colorAttribute(theme, android.R .attr.statusBarColor)
40
40
val useLightStatusBar = booleanAttribute(theme, android.R .attr.windowLightStatusBar)
41
41
42
- window.statusBarColor.animateColorTo(statusBarColor) {
43
- window.statusBarColor = it
42
+ window? .statusBarColor? .animateColorTo(statusBarColor) {
43
+ window? .statusBarColor = it
44
44
}
45
45
46
46
@Suppress(" DEPRECATION" )
@@ -51,8 +51,8 @@ internal class TurboWindowThemeObserver(val destination: TurboNavDestination) :
51
51
private fun updateNavigationBar (theme : Theme ) {
52
52
val navigationBarColor = colorAttribute(theme, android.R .attr.navigationBarColor)
53
53
54
- window.navigationBarColor.animateColorTo(navigationBarColor) {
55
- window.navigationBarColor = it
54
+ window? .navigationBarColor? .animateColorTo(navigationBarColor) {
55
+ window? .navigationBarColor = it
56
56
}
57
57
58
58
// Light navigation bars are only available in API 27+
@@ -76,6 +76,7 @@ internal class TurboWindowThemeObserver(val destination: TurboNavDestination) :
76
76
77
77
@RequiresApi(Build .VERSION_CODES .R )
78
78
private fun updateSystemBarsAppearance (useLightSystemBars : Boolean ) {
79
+ val window = window ? : return
79
80
val appearance = when (useLightSystemBars) {
80
81
true -> APPEARANCE_LIGHT_STATUS_BARS
81
82
else -> 0
@@ -94,6 +95,7 @@ internal class TurboWindowThemeObserver(val destination: TurboNavDestination) :
94
95
95
96
@Suppress(" DEPRECATION" )
96
97
private fun updateSystemUiVisibility (useLightSystemBar : Boolean , flag : Int ) {
98
+ val window = window ? : return
97
99
val flags = when (useLightSystemBar) {
98
100
true -> window.decorView.systemUiVisibility or flag
99
101
else -> window.decorView.systemUiVisibility and flag.inv ()
0 commit comments