From ce740c39b16a9b021973b9db3e312c6fbbf85acf Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Fri, 31 Jul 2026 19:57:27 +0200 Subject: [PATCH] fix(theme): drive system bar icons from the in-app light/dark choice (#70) --- .../jeanlucmakiola/calendula/MainActivity.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/MainActivity.kt b/app/src/main/java/de/jeanlucmakiola/calendula/MainActivity.kt index 0a0c20f..16094d1 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/MainActivity.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/MainActivity.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.provider.CalendarContract +import androidx.activity.SystemBarStyle import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity @@ -12,6 +13,7 @@ import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -50,6 +52,10 @@ import kotlinx.datetime.toLocalDateTime import kotlin.time.Clock import kotlin.time.Instant +// The nav-bar scrims androidx's own enableEdgeToEdge() defaults to. +private val LIGHT_NAV_SCRIM = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF) +private val DARK_NAV_SCRIM = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b) + @AndroidEntryPoint class MainActivity : AppCompatActivity() { @@ -113,6 +119,22 @@ class MainActivity : AppCompatActivity() { ThemeMode.LIGHT -> false ThemeMode.DARK -> true } + // The bare enableEdgeToEdge() in onCreate reads the night resource + // qualifier, not the in-app override — re-apply it from the resolved + // theme so the bar icons follow the app's light/dark choice. + DisposableEffect(darkTheme) { + enableEdgeToEdge( + statusBarStyle = SystemBarStyle.auto( + android.graphics.Color.TRANSPARENT, + android.graphics.Color.TRANSPARENT, + ) { darkTheme }, + navigationBarStyle = SystemBarStyle.auto( + LIGHT_NAV_SCRIM, + DARK_NAV_SCRIM, + ) { darkTheme }, + ) + onDispose {} + } // The app-wide clock convention: the time-format preference resolved // against the device's 24-hour system setting, provided once here so // every time label reads it via LocalUse24HourFormat.