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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 4 deletions

View File

@ -153,17 +153,17 @@ fun AboutSheet(
)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
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) },
label = { Text("system", fontFamily = FontFamily.Monospace) }
)
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) },
label = { Text("light", fontFamily = FontFamily.Monospace) }
)
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) },
label = { Text("dark", fontFamily = FontFamily.Monospace) }
)

View File

@ -1,13 +1,20 @@
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.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
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
private val DarkColorScheme = darkColorScheme(
@ -55,6 +62,27 @@ fun BitchatTheme(
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(
colorScheme = colorScheme,
typography = Typography,

View File

@ -8,7 +8,13 @@ import kotlinx.coroutines.flow.StateFlow
* App theme preference: System default, Light, or Dark.
*/
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
}
/**