Skip to content

Commit

Permalink
Update Status Bar to Match Theme Colors Dynamically (#2722)
Browse files Browse the repository at this point in the history
  • Loading branch information
revanthkumarJ authored Dec 19, 2024
1 parent d123dd4 commit 3bbcd02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion androidApp/src/main/kotlin/org/mifos/mobile/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3bbcd02

Please sign in to comment.