Skip to content

Commit

Permalink
Status bar and navigation bar styles updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Saifuddin53 committed Oct 10, 2024
1 parent 771fbda commit 26379d6
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 27 deletions.
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
4 changes: 4 additions & 0 deletions androidApp/src/main/res/values-night/color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="status_bar">#FF1B1B1F</color> // dark/color.xml
</resources>
12 changes: 12 additions & 0 deletions androidApp/src/main/res/values-night/theme.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<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
44 changes: 33 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,40 @@
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">
<!-- <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>-->
<!-- </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>-->
<!-- </style>-->

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

<!-- 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 @@ -9,18 +9,12 @@
*/
package org.mifos.mobile.core.designsystem.theme

import android.app.Activity
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.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat

private val LightThemeColors = lightColorScheme(
primary = LightPrimary,
Expand All @@ -39,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 All @@ -56,15 +50,6 @@ fun MifosMobileTheme(
else -> LightThemeColors
}

val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightStatusBars = true
}
}

MaterialTheme(
colorScheme = colors,
content = content,
Expand Down

0 comments on commit 26379d6

Please sign in to comment.