diff --git a/cmp-navigation/src/commonMain/kotlin/cmp/navigation/ComposeApp.kt b/cmp-navigation/src/commonMain/kotlin/cmp/navigation/ComposeApp.kt index 7830b30e0c..116b8af430 100644 --- a/cmp-navigation/src/commonMain/kotlin/cmp/navigation/ComposeApp.kt +++ b/cmp-navigation/src/commonMain/kotlin/cmp/navigation/ComposeApp.kt @@ -9,11 +9,13 @@ */ package cmp.navigation +import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.lifecycle.compose.collectAsStateWithLifecycle import cmp.navigation.rootnav.RootNavScreen +import com.mifos.core.datastore.model.DarkThemeConfig import com.mifos.core.designsystem.theme.MifosTheme import com.mifos.core.ui.util.EventsEffect import org.koin.compose.viewmodel.koinViewModel @@ -36,8 +38,14 @@ fun ComposeApp( } } + val darkTheme = when (uiState.darkThemeConfig) { + DarkThemeConfig.DARK -> true + DarkThemeConfig.LIGHT -> false + DarkThemeConfig.FOLLOW_SYSTEM -> isSystemInDarkTheme() + } + MifosTheme( - darkTheme = uiState.darkTheme, + darkTheme = darkTheme, androidTheme = uiState.isAndroidTheme, shouldDisplayDynamicTheming = uiState.isDynamicColorsEnabled, ) { diff --git a/cmp-navigation/src/commonMain/kotlin/cmp/navigation/ComposeAppViewModel.kt b/cmp-navigation/src/commonMain/kotlin/cmp/navigation/ComposeAppViewModel.kt index 0a348e1e34..2851ccc569 100644 --- a/cmp-navigation/src/commonMain/kotlin/cmp/navigation/ComposeAppViewModel.kt +++ b/cmp-navigation/src/commonMain/kotlin/cmp/navigation/ComposeAppViewModel.kt @@ -28,7 +28,7 @@ class ComposeAppViewModel( private val networkMonitor: NetworkMonitor, ) : BaseViewModel( initialState = AppState( - darkTheme = false, + darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM, isAndroidTheme = false, isDynamicColorsEnabled = false, ), @@ -66,7 +66,7 @@ class ComposeAppViewModel( private fun handleAppThemeUpdated(action: AppAction.Internal.ThemeUpdate) { mutableStateFlow.update { - it.copy(darkTheme = action.theme == DarkThemeConfig.DARK) + it.copy(darkThemeConfig = action.theme) } sendEvent(AppEvent.UpdateAppTheme(osValue = action.theme.osValue)) } @@ -77,7 +77,7 @@ class ComposeAppViewModel( } data class AppState( - val darkTheme: Boolean, + val darkThemeConfig: DarkThemeConfig, val isAndroidTheme: Boolean, val isDynamicColorsEnabled: Boolean, )