From 7e340af48e7bcdf061c5832afa82a78c7bb998d1 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Thu, 15 Sep 2022 23:39:19 +0300 Subject: [PATCH] System theme fix (#1059) --- .../app/src/main/java/chat/simplex/app/ui/theme/Theme.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/ui/theme/Theme.kt b/apps/android/app/src/main/java/chat/simplex/app/ui/theme/Theme.kt index a475beed7c..e5b7bba032 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/ui/theme/Theme.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/ui/theme/Theme.kt @@ -1,9 +1,12 @@ package chat.simplex.app.ui.theme +import android.app.UiModeManager +import android.content.Context import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color +import chat.simplex.app.SimplexApp import kotlinx.coroutines.flow.MutableStateFlow enum class DefaultTheme { @@ -35,7 +38,11 @@ val LightColorPalette = lightColors( // onSurface = Color.Black, ) -val CurrentColors: MutableStateFlow> = MutableStateFlow(ThemeManager.currentColors(true)) +val CurrentColors: MutableStateFlow> = MutableStateFlow(ThemeManager.currentColors(isInNightMode())) + +// Non-@Composable implementation +private fun isInNightMode() = + (SimplexApp.context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager).nightMode == UiModeManager.MODE_NIGHT_YES @Composable fun isInDarkTheme(): Boolean = !CurrentColors.collectAsState().value.first.isLight