Ensure that the manual dark theme is rendering correctly regarding night resource and keyboard.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user