Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Status Bar to Match Theme Colors Dynamically #2711

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions androidApp/src/main/kotlin/org/mifos/mobile/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
*/
package org.mifos.mobile

import android.graphics.Color
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
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 +35,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 @@ -73,6 +80,8 @@ class HomeActivity : ComponentActivity() {

val appState = rememberMifosMobileState(networkMonitor = networkMonitor)

val darkTheme = isSystemInDarkTheme()

val navDestination = when (uiState) {
is Success -> if ((uiState as Success).userData.isAuthenticated) {
PASSCODE_GRAPH
Expand All @@ -83,6 +92,20 @@ class HomeActivity : ComponentActivity() {
else -> AUTH_GRAPH
}

DisposableEffect(darkTheme) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
Color.TRANSPARENT,
Color.TRANSPARENT
) { darkTheme },
navigationBarStyle = SystemBarStyle.auto(
lightScrim.toArgb(),
darkScrim.toArgb()
) { darkTheme },
)
onDispose {}
}

CompositionLocalProvider {
MifosMobileTheme {
RootNavGraph(
Expand Down
13 changes: 13 additions & 0 deletions androidApp/src/main/res/values-night/color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.

See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
-->
<resources>
<color name="status_bar">#FF1B1B1F</color> // dark/color.xml
</resources>
21 changes: 21 additions & 0 deletions androidApp/src/main/res/values-night/theme.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.

See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
-->
<resources xmlns:tools="http://schemas.android.com/tools">

<style name="NightAdjusted.Theme" parent="android:Theme.Material.NoActionBar">
<item name="android:statusBarColor">@color/status_bar</item>
</style>

<style name="NightAdjusted.Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
</style>

</resources>
1 change: 1 addition & 0 deletions androidApp/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<color name="gray_bright">#33CCCCCC</color>

<!-- Material design colors -->
<color name="status_bar">#FFFEFBFF</color>

<!-- New UI color palette -->
<!--<color name="primary">#068799</color>-->
Expand Down
26 changes: 15 additions & 11 deletions androidApp/src/main/res/values/splash.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@

See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
-->
<resources>
<style name="Theme.MifosSplash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#FFFDFDF5</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/splash_icon</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
<item name="windowSplashScreenAnimationDuration">10</item>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Allows us to override night specific attributes in the
values-night folder. -->
<style name="NightAdjusted.Theme" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@color/status_bar</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@color/background</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
<!-- The final theme we use -->
<style name="Theme.MifosSplash" parent="NightAdjusted.Theme" />

<style name="NightAdjusted.Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowLightNavigationBar" tools:targetApi="27">true</item>
</style>

<style name="Theme.Mifos.Splash" parent="NightAdjusted.Theme.Splash">
<item name="windowSplashScreenAnimatedIcon">@drawable/splash_icon</item>
<item name="postSplashScreenTheme">@style/Theme.MifosSplash</item>
</style>
</resources>
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) // Light scrim with 50% opacity
val darkScrim = Color(0x80000000) // Dark scrim with 50% opacity
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private val DarkThemeColors = darkColorScheme(
secondary = Black1,
error = RedErrorDark,
background = BackgroundDark,
surface = Black1,
surface = BackgroundDark,
onSurface = Color.White,
onSecondary = Color.White,
outlineVariant = Color.White,
Expand Down
Loading