|
| 1 | +/* |
| 2 | + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package com.amplifyframework.ui.authenticator.theme |
| 17 | + |
| 18 | +import androidx.compose.foundation.isSystemInDarkTheme |
| 19 | +import androidx.compose.material3.MaterialTheme |
| 20 | +import androidx.compose.material3.darkColorScheme |
| 21 | +import androidx.compose.material3.lightColorScheme |
| 22 | +import androidx.compose.runtime.Composable |
| 23 | + |
| 24 | +private val LightColors = lightColorScheme( |
| 25 | + primary = md_theme_light_primary, |
| 26 | + onPrimary = md_theme_light_onPrimary, |
| 27 | + primaryContainer = md_theme_light_primaryContainer, |
| 28 | + onPrimaryContainer = md_theme_light_onPrimaryContainer, |
| 29 | + secondary = md_theme_light_secondary, |
| 30 | + onSecondary = md_theme_light_onSecondary, |
| 31 | + secondaryContainer = md_theme_light_secondaryContainer, |
| 32 | + onSecondaryContainer = md_theme_light_onSecondaryContainer, |
| 33 | + tertiary = md_theme_light_tertiary, |
| 34 | + onTertiary = md_theme_light_onTertiary, |
| 35 | + tertiaryContainer = md_theme_light_tertiaryContainer, |
| 36 | + onTertiaryContainer = md_theme_light_onTertiaryContainer, |
| 37 | + error = md_theme_light_error, |
| 38 | + errorContainer = md_theme_light_errorContainer, |
| 39 | + onError = md_theme_light_onError, |
| 40 | + onErrorContainer = md_theme_light_onErrorContainer, |
| 41 | + background = md_theme_light_background, |
| 42 | + onBackground = md_theme_light_onBackground, |
| 43 | + surface = md_theme_light_surface, |
| 44 | + onSurface = md_theme_light_onSurface, |
| 45 | + surfaceVariant = md_theme_light_surfaceVariant, |
| 46 | + onSurfaceVariant = md_theme_light_onSurfaceVariant, |
| 47 | + outline = md_theme_light_outline, |
| 48 | + inverseOnSurface = md_theme_light_inverseOnSurface, |
| 49 | + inverseSurface = md_theme_light_inverseSurface, |
| 50 | + inversePrimary = md_theme_light_inversePrimary, |
| 51 | + surfaceTint = md_theme_light_surfaceTint |
| 52 | +) |
| 53 | + |
| 54 | +private val DarkColors = darkColorScheme( |
| 55 | + primary = md_theme_dark_primary, |
| 56 | + onPrimary = md_theme_dark_onPrimary, |
| 57 | + primaryContainer = md_theme_dark_primaryContainer, |
| 58 | + onPrimaryContainer = md_theme_dark_onPrimaryContainer, |
| 59 | + secondary = md_theme_dark_secondary, |
| 60 | + onSecondary = md_theme_dark_onSecondary, |
| 61 | + secondaryContainer = md_theme_dark_secondaryContainer, |
| 62 | + onSecondaryContainer = md_theme_dark_onSecondaryContainer, |
| 63 | + tertiary = md_theme_dark_tertiary, |
| 64 | + onTertiary = md_theme_dark_onTertiary, |
| 65 | + tertiaryContainer = md_theme_dark_tertiaryContainer, |
| 66 | + onTertiaryContainer = md_theme_dark_onTertiaryContainer, |
| 67 | + error = md_theme_dark_error, |
| 68 | + errorContainer = md_theme_dark_errorContainer, |
| 69 | + onError = md_theme_dark_onError, |
| 70 | + onErrorContainer = md_theme_dark_onErrorContainer, |
| 71 | + background = md_theme_dark_background, |
| 72 | + onBackground = md_theme_dark_onBackground, |
| 73 | + surface = md_theme_dark_surface, |
| 74 | + onSurface = md_theme_dark_onSurface, |
| 75 | + surfaceVariant = md_theme_dark_surfaceVariant, |
| 76 | + onSurfaceVariant = md_theme_dark_onSurfaceVariant, |
| 77 | + outline = md_theme_dark_outline, |
| 78 | + inverseOnSurface = md_theme_dark_inverseOnSurface, |
| 79 | + inverseSurface = md_theme_dark_inverseSurface, |
| 80 | + inversePrimary = md_theme_dark_inversePrimary, |
| 81 | + surfaceTint = md_theme_dark_surfaceTint |
| 82 | +) |
| 83 | + |
| 84 | +@Composable |
| 85 | +fun AmplifyTheme( |
| 86 | + useDarkTheme: Boolean = isSystemInDarkTheme(), |
| 87 | + content: @Composable () -> Unit |
| 88 | +) { |
| 89 | + val colors = if (!useDarkTheme) { |
| 90 | + LightColors |
| 91 | + } else { |
| 92 | + DarkColors |
| 93 | + } |
| 94 | + |
| 95 | + MaterialTheme( |
| 96 | + colorScheme = colors, |
| 97 | + content = content |
| 98 | + ) |
| 99 | +} |
0 commit comments