From 3bbcd024dfa4b513f9863b27f49d7ad143bdce9b Mon Sep 17 00:00:00 2001 From: JILAKARA REVANTH KUMAR <146642552+revanthkumarJ@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:15:12 +0530 Subject: [PATCH] Update Status Bar to Match Theme Colors Dynamically (#2722) --- .../main/kotlin/org/mifos/mobile/HomeActivity.kt | 13 ++++++++++++- .../mifos/mobile/core/designsystem/theme/Color.kt | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/androidApp/src/main/kotlin/org/mifos/mobile/HomeActivity.kt b/androidApp/src/main/kotlin/org/mifos/mobile/HomeActivity.kt index 1de7ca6c6..5fa0cdc27 100644 --- a/androidApp/src/main/kotlin/org/mifos/mobile/HomeActivity.kt +++ b/androidApp/src/main/kotlin/org/mifos/mobile/HomeActivity.kt @@ -14,10 +14,13 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels +import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.compose.ui.graphics.toArgb import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope @@ -30,6 +33,8 @@ import kotlinx.coroutines.launch import org.mifos.mobile.HomeActivityUiState.Success import org.mifos.mobile.core.data.utils.NetworkMonitor import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme +import org.mifos.mobile.core.designsystem.theme.darkScrim +import org.mifos.mobile.core.designsystem.theme.lightScrim import org.mifos.mobile.navigation.MifosNavGraph.AUTH_GRAPH import org.mifos.mobile.navigation.MifosNavGraph.PASSCODE_GRAPH import org.mifos.mobile.navigation.RootNavGraph @@ -71,7 +76,7 @@ class HomeActivity : ComponentActivity() { val navController = rememberNavController() val appState = rememberMifosMobileState(networkMonitor = networkMonitor) - + val darkTheme= isSystemInDarkTheme() val navDestination = when (uiState) { is Success -> if ((uiState as Success).userData.isAuthenticated) { PASSCODE_GRAPH @@ -82,6 +87,12 @@ class HomeActivity : ComponentActivity() { else -> AUTH_GRAPH } + DisposableEffect(darkTheme) { + window?.statusBarColor = if (darkTheme) darkScrim.toArgb() else lightScrim.toArgb() + window?.navigationBarColor = if (darkTheme) darkScrim.toArgb() else lightScrim.toArgb() + onDispose {} + } + CompositionLocalProvider { MifosMobileTheme { RootNavGraph( diff --git a/core/designsystem/src/main/kotlin/org/mifos/mobile/core/designsystem/theme/Color.kt b/core/designsystem/src/main/kotlin/org/mifos/mobile/core/designsystem/theme/Color.kt index 5f6ec2a0b..b08093456 100644 --- a/core/designsystem/src/main/kotlin/org/mifos/mobile/core/designsystem/theme/Color.kt +++ b/core/designsystem/src/main/kotlin/org/mifos/mobile/core/designsystem/theme/Color.kt @@ -35,3 +35,6 @@ val DarkGray = Color(0xBB666666) val GreenSuccess = Color(0xff14c416) val LightSurfaceTint = Color(0xFF325CA8) val DarkSurfaceTint = Color(0xFFAEC6FF) + +val lightScrim = Color(0x80FFFFFF) +val darkScrim = Color(0x80000000) \ No newline at end of file