From 32f5c018d5d7632bcd21d1b05f7e0995e4ef9d2e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 18 Jul 2024 14:37:47 +0200 Subject: [PATCH] Ensure that the manual dark theme is rendering correctly regarding night resource and keyboard. --- .../designsystem/theme/ElementThemeApp.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ElementThemeApp.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ElementThemeApp.kt index 4c20c02e9b..6dc7c41c77 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ElementThemeApp.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ElementThemeApp.kt @@ -16,7 +16,9 @@ package io.element.android.libraries.designsystem.theme +import androidx.appcompat.app.AppCompatDelegate import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember @@ -29,6 +31,9 @@ import io.element.android.libraries.preferences.api.store.AppPreferencesStore /** * Theme to use for all the regular screens of the application. * Will manage the light / dark theme based on the user preference. + * Will also ensure that the system is applying the correct global theme + * to the application, especially when the system is light and the application + * is forced to use dark theme. */ @Composable fun ElementThemeApp( @@ -39,6 +44,15 @@ fun ElementThemeApp( appPreferencesStore.getThemeFlow().mapToTheme() } .collectAsState(initial = Theme.System) + LaunchedEffect(theme) { + AppCompatDelegate.setDefaultNightMode( + when (theme) { + Theme.System -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + Theme.Light -> AppCompatDelegate.MODE_NIGHT_NO + Theme.Dark -> AppCompatDelegate.MODE_NIGHT_YES + } + ) + } ElementTheme( darkTheme = theme.isDark(), content = content,