diff --git a/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt b/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt index 0422328f9..d9749898e 100644 --- a/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt +++ b/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt @@ -1,6 +1,7 @@ package com.reactnativekeyboardcontroller.extensions -import android.content.res.Configuration +import android.content.Context +import android.os.Build import com.facebook.react.bridge.ReactContext import com.facebook.react.bridge.WritableMap import com.facebook.react.modules.core.DeviceEventManagerModule @@ -38,10 +39,16 @@ fun ThemedReactContext?.emitEvent( val ThemedReactContext?.appearance: String get() = - this?.let { - when (it.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) { - Configuration.UI_MODE_NIGHT_NO -> "light" - Configuration.UI_MODE_NIGHT_YES -> "dark" - else -> "default" - } - } ?: "default" + when { + this == null -> "default" + isSystemDarkMode(this) -> "dark" + else -> "light" + } + +private fun isSystemDarkMode(context: Context): Boolean = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + (context.getSystemService(Context.UI_MODE_SERVICE) as? android.app.UiModeManager) + ?.nightMode == android.app.UiModeManager.MODE_NIGHT_YES + } else { + false + }