What's the general guidance around extending `colo...
# compose
x
What's the general guidance around extending
colorScheme
for Material 3? In Material 2 I used to do
Copy code
val Colors.alertHigh: Color
  @Composable get() =
    if (!isSystemInDarkTheme()) Color(0xFFD0011C) else Color(0xFFFF3B2F)
with Material 3 only difference was the
Colors
ColorScheme
, but as you can see the custom colours tend to stand out from the rest.
m
To be honest, your colors should live inside something that's part of a composition local so that they can change along with the theme instead of being limited to just light/dark like you have above. You really only need to make the light/dark decision in a single place, and that's where you are setting up your theme (see the MyTheme function)
Copy code
data class MyColors(
    val alertHigh: Color
)

fun myColorsLight() = MyColors(
    alertHigh = Color(0xFFD0011C)
)

fun myColorsDark() = MyColors(
    alertHigh = Color(0xFFFF3B2F)
)

val LocalMyColors = staticCompositionLocalOf { 
    myColorsLight()
}

val MaterialTheme.myColors: MyColors
    @Composable
    get() = LocalMyColors.current

@Composable
fun MyTheme(content: @Composable () -> Unit) {
    MaterialTheme {
        CompositionLocalProvider(
            LocalMyColors provides if (isSystemInDarkTheme()) myColorsDark() else myColorsLight()
        ) {
            
        }
    }
}
(yes this is material2, but it should be not horribly different in material3)