Ensure that the manual dark theme is rendering correctly regarding night resource and keyboard.

This commit is contained in:
Benoit Marty
2024-07-18 14:37:47 +02:00
parent b8a579778d
commit 32f5c018d5

View File

@@ -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,