Fix system bar colors for dark theme (#368)

* Add computed properties for ThemePreference enum

* Fix system bar colors for dark theme
This commit is contained in:
Héctor de Isidro
2025-09-02 14:24:26 +02:00
committed by GitHub
parent 8a55414143
commit e380408b28
3 changed files with 38 additions and 4 deletions
@@ -153,17 +153,17 @@ fun AboutSheet(
) )
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
FilterChip( FilterChip(
selected = themePref == com.bitchat.android.ui.theme.ThemePreference.System, selected = themePref.isSystem,
onClick = { com.bitchat.android.ui.theme.ThemePreferenceManager.set(context, com.bitchat.android.ui.theme.ThemePreference.System) }, onClick = { com.bitchat.android.ui.theme.ThemePreferenceManager.set(context, com.bitchat.android.ui.theme.ThemePreference.System) },
label = { Text("system", fontFamily = FontFamily.Monospace) } label = { Text("system", fontFamily = FontFamily.Monospace) }
) )
FilterChip( FilterChip(
selected = themePref == com.bitchat.android.ui.theme.ThemePreference.Light, selected = themePref.isLight,
onClick = { com.bitchat.android.ui.theme.ThemePreferenceManager.set(context, com.bitchat.android.ui.theme.ThemePreference.Light) }, onClick = { com.bitchat.android.ui.theme.ThemePreferenceManager.set(context, com.bitchat.android.ui.theme.ThemePreference.Light) },
label = { Text("light", fontFamily = FontFamily.Monospace) } label = { Text("light", fontFamily = FontFamily.Monospace) }
) )
FilterChip( FilterChip(
selected = themePref == com.bitchat.android.ui.theme.ThemePreference.Dark, selected = themePref.isDark,
onClick = { com.bitchat.android.ui.theme.ThemePreferenceManager.set(context, com.bitchat.android.ui.theme.ThemePreference.Dark) }, onClick = { com.bitchat.android.ui.theme.ThemePreferenceManager.set(context, com.bitchat.android.ui.theme.ThemePreference.Dark) },
label = { Text("dark", fontFamily = FontFamily.Monospace) } label = { Text("dark", fontFamily = FontFamily.Monospace) }
) )
@@ -1,13 +1,20 @@
package com.bitchat.android.ui.theme package com.bitchat.android.ui.theme
import android.app.Activity
import android.os.Build
import android.view.View
import android.view.WindowInsetsController
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
// Colors that match the iOS bitchat theme // Colors that match the iOS bitchat theme
private val DarkColorScheme = darkColorScheme( private val DarkColorScheme = darkColorScheme(
@@ -55,6 +62,27 @@ fun BitchatTheme(
val colorScheme = if (shouldUseDark) DarkColorScheme else LightColorScheme val colorScheme = if (shouldUseDark) DarkColorScheme else LightColorScheme
val view = LocalView.current
SideEffect {
(view.context as? Activity)?.window?.let { window ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.setSystemBarsAppearance(
if (!shouldUseDark) WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS else 0,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
} else {
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility = if (!shouldUseDark) {
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else 0
}
window.navigationBarColor = colorScheme.background.toArgb()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false
}
}
}
MaterialTheme( MaterialTheme(
colorScheme = colorScheme, colorScheme = colorScheme,
typography = Typography, typography = Typography,
@@ -8,7 +8,13 @@ import kotlinx.coroutines.flow.StateFlow
* App theme preference: System default, Light, or Dark. * App theme preference: System default, Light, or Dark.
*/ */
enum class ThemePreference { enum class ThemePreference {
System, Light, Dark System,
Light,
Dark;
val isSystem : Boolean get() = this == System
val isLight : Boolean get() = this == Light
val isDark : Boolean get() = this == Dark
} }
/** /**