mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-24 22:45:20 +00:00
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:
@@ -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) }
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user