|
| 1 | +package org.mifos.mobilewallet.mifospay.designsystem.theme |
| 2 | + |
| 3 | +import androidx.compose.foundation.isSystemInDarkTheme |
| 4 | +import androidx.compose.material3.MaterialTheme |
| 5 | +import androidx.compose.material3.darkColorScheme |
| 6 | +import androidx.compose.material3.lightColorScheme |
| 7 | +import androidx.compose.runtime.Composable |
| 8 | +import androidx.compose.runtime.CompositionLocalProvider |
| 9 | +import androidx.compose.ui.unit.dp |
| 10 | + |
| 11 | +private val LightDefaultColorScheme = lightColorScheme( |
| 12 | + primary = md_theme_light_primary, |
| 13 | + onPrimary = md_theme_light_onPrimary, |
| 14 | + primaryContainer = md_theme_light_primaryContainer, |
| 15 | + onPrimaryContainer = md_theme_light_onPrimaryContainer, |
| 16 | + secondary = md_theme_light_secondary, |
| 17 | + onSecondary = md_theme_light_onSecondary, |
| 18 | + secondaryContainer = md_theme_light_secondaryContainer, |
| 19 | + onSecondaryContainer = md_theme_light_onSecondaryContainer, |
| 20 | + tertiary = md_theme_light_tertiary, |
| 21 | + onTertiary = md_theme_light_onTertiary, |
| 22 | + tertiaryContainer = md_theme_light_tertiaryContainer, |
| 23 | + onTertiaryContainer = md_theme_light_onTertiaryContainer, |
| 24 | + error = md_theme_light_error, |
| 25 | + errorContainer = md_theme_light_errorContainer, |
| 26 | + onError = md_theme_light_onError, |
| 27 | + onErrorContainer = md_theme_light_onErrorContainer, |
| 28 | + background = md_theme_light_background, |
| 29 | + onBackground = md_theme_light_onBackground, |
| 30 | + surface = md_theme_light_surface, |
| 31 | + onSurface = md_theme_light_onSurface, |
| 32 | + surfaceVariant = md_theme_light_surfaceVariant, |
| 33 | + onSurfaceVariant = md_theme_light_onSurfaceVariant, |
| 34 | + outline = md_theme_light_outline, |
| 35 | + inverseOnSurface = md_theme_light_inverseOnSurface, |
| 36 | + inverseSurface = md_theme_light_inverseSurface, |
| 37 | + inversePrimary = md_theme_light_inversePrimary, |
| 38 | + surfaceTint = md_theme_light_surfaceTint, |
| 39 | + outlineVariant = md_theme_light_outlineVariant, |
| 40 | + scrim = md_theme_light_scrim, |
| 41 | +) |
| 42 | + |
| 43 | + |
| 44 | +private val DarkDefaultColorScheme = darkColorScheme( |
| 45 | + primary = md_theme_dark_primary, |
| 46 | + onPrimary = md_theme_dark_onPrimary, |
| 47 | + primaryContainer = md_theme_dark_primaryContainer, |
| 48 | + onPrimaryContainer = md_theme_dark_onPrimaryContainer, |
| 49 | + secondary = md_theme_dark_secondary, |
| 50 | + onSecondary = md_theme_dark_onSecondary, |
| 51 | + secondaryContainer = md_theme_dark_secondaryContainer, |
| 52 | + onSecondaryContainer = md_theme_dark_onSecondaryContainer, |
| 53 | + tertiary = md_theme_dark_tertiary, |
| 54 | + onTertiary = md_theme_dark_onTertiary, |
| 55 | + tertiaryContainer = md_theme_dark_tertiaryContainer, |
| 56 | + onTertiaryContainer = md_theme_dark_onTertiaryContainer, |
| 57 | + error = md_theme_dark_error, |
| 58 | + errorContainer = md_theme_dark_errorContainer, |
| 59 | + onError = md_theme_dark_onError, |
| 60 | + onErrorContainer = md_theme_dark_onErrorContainer, |
| 61 | + background = md_theme_dark_background, |
| 62 | + onBackground = md_theme_dark_onBackground, |
| 63 | + surface = md_theme_dark_surface, |
| 64 | + onSurface = md_theme_dark_onSurface, |
| 65 | + surfaceVariant = md_theme_dark_surfaceVariant, |
| 66 | + onSurfaceVariant = md_theme_dark_onSurfaceVariant, |
| 67 | + outline = md_theme_dark_outline, |
| 68 | + inverseOnSurface = md_theme_dark_inverseOnSurface, |
| 69 | + inverseSurface = md_theme_dark_inverseSurface, |
| 70 | + inversePrimary = md_theme_dark_inversePrimary, |
| 71 | + surfaceTint = md_theme_dark_surfaceTint, |
| 72 | + outlineVariant = md_theme_dark_outlineVariant, |
| 73 | + scrim = md_theme_dark_scrim, |
| 74 | +) |
| 75 | + |
| 76 | +@Composable |
| 77 | +fun MifosTheme( |
| 78 | + darkTheme: Boolean = isSystemInDarkTheme(), |
| 79 | + // Dynamic color is available on Android 12+ |
| 80 | + dynamicColor: Boolean = true, |
| 81 | + content: @Composable () -> Unit |
| 82 | +) { |
| 83 | + // Color scheme |
| 84 | + val colorScheme = when { |
| 85 | + else -> if (darkTheme) DarkDefaultColorScheme else LightDefaultColorScheme |
| 86 | + } |
| 87 | + val defaultGradientColors = GradientColors( |
| 88 | + top = colorScheme.inverseOnSurface, |
| 89 | + bottom = colorScheme.primaryContainer, |
| 90 | + container = colorScheme.surface, |
| 91 | + ) |
| 92 | + val gradientColors = when { |
| 93 | + else -> defaultGradientColors |
| 94 | + } |
| 95 | + // Background theme |
| 96 | + val defaultBackgroundTheme = BackgroundTheme( |
| 97 | + color = colorScheme.surface, |
| 98 | + tonalElevation = 2.dp, |
| 99 | + ) |
| 100 | + val backgroundTheme = when { |
| 101 | + else -> defaultBackgroundTheme |
| 102 | + } |
| 103 | + val tintTheme = when { |
| 104 | + else -> TintTheme() |
| 105 | + } |
| 106 | + // Composition locals |
| 107 | + CompositionLocalProvider( |
| 108 | + LocalGradientColors provides gradientColors, |
| 109 | + LocalBackgroundTheme provides backgroundTheme, |
| 110 | + LocalTintTheme provides tintTheme, |
| 111 | + ) { |
| 112 | + MaterialTheme( |
| 113 | + colorScheme = colorScheme, |
| 114 | + typography = MifosTypography, |
| 115 | + content = content, |
| 116 | + ) |
| 117 | + } |
| 118 | +} |
0 commit comments