Skip to content

Commit 80063a6

Browse files
fix(android): Fix Dark Mode detection on Android (#8058)
Co-authored-by: Georgy Steshin <[email protected]>
1 parent 6ebb7b6 commit 80063a6

File tree

1 file changed

+8
-4
lines changed
  • lib/android/app/src/main/java/com/reactnativenavigation/utils

1 file changed

+8
-4
lines changed

lib/android/app/src/main/java/com/reactnativenavigation/utils/Context.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package com.reactnativenavigation.utils
22

33
import android.content.Context
44
import android.content.res.Configuration
5-
import android.content.res.Configuration.UI_MODE_NIGHT_YES
5+
import androidx.appcompat.app.AppCompatDelegate
66
import com.facebook.react.ReactApplication
77
import com.reactnativenavigation.NavigationApplication
88

99
fun Context.isDebug(): Boolean {
1010
return (applicationContext as ReactApplication).reactNativeHost.useDeveloperSupport
1111
}
1212
fun isDarkMode() = NavigationApplication.instance.isDarkMode()
13-
fun Context.isDarkMode(): Boolean =
14-
(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == UI_MODE_NIGHT_YES
15-
fun Configuration.isDarkMode() = (uiMode and Configuration.UI_MODE_NIGHT_MASK) == UI_MODE_NIGHT_YES
13+
fun Context.isDarkMode(): Boolean = when (AppCompatDelegate.getDefaultNightMode()) {
14+
AppCompatDelegate.MODE_NIGHT_YES -> true
15+
AppCompatDelegate.MODE_NIGHT_NO -> false
16+
else -> resources.configuration.isDarkMode()
17+
}
18+
fun Configuration.isDarkMode() =
19+
(uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES

0 commit comments

Comments
 (0)