• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
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  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.photopicker.core.theme
18 
19 import androidx.compose.material3.ColorScheme
20 import androidx.compose.runtime.compositionLocalOf
21 import androidx.compose.ui.graphics.Color
22 
23 /** Provider for the compose tree */
24 val LocalFixedAccentColors =
<lambda>null25     compositionLocalOf<FixedAccentColors> { error("No LocalFixedAccentColors provided") }
26 
27 /**
28  * This fills a gap in the compose Material3 implementation colors roles spec where the fixed accent
29  * color roles are not specified in the primary generated color scheme.
30  *
31  * @See https://m3.material.io/styles/color/roles
32  *
33  * TODO(b/348616038): Remove this implementation when the roles are present in the MaterialTheme
34  */
35 data class FixedAccentColors
36 private constructor(
37     val primaryFixed: Color,
38     val onPrimaryFixed: Color,
39     val secondaryFixed: Color,
40     val onSecondaryFixed: Color,
41     val tertiaryFixed: Color,
42     val onTertiaryFixed: Color,
43     val primaryFixedDim: Color,
44     val secondaryFixedDim: Color,
45     val tertiaryFixedDim: Color,
46 ) {
47 
48     companion object {
49         /**
50          * Builds a [FixedAccentColors] by mapping the fixed colors to their corresponding color
51          * tokens
52          */
buildnull53         fun build(lightColors: ColorScheme, darkColors: ColorScheme): FixedAccentColors {
54 
55             return FixedAccentColors(
56                 primaryFixed = lightColors.primaryContainer,
57                 onPrimaryFixed = lightColors.onPrimaryContainer,
58                 secondaryFixed = lightColors.secondaryContainer,
59                 onSecondaryFixed = lightColors.onSecondaryContainer,
60                 tertiaryFixed = lightColors.tertiaryContainer,
61                 onTertiaryFixed = lightColors.onTertiaryContainer,
62                 primaryFixedDim = darkColors.primary,
63                 secondaryFixedDim = darkColors.secondary,
64                 tertiaryFixedDim = darkColors.tertiary
65             )
66         }
67     }
68 }
69