bbade_
12/15/2021, 12:20 AMColumn
Button1
*OddUi*
Button3
Lets say i wanted to override primary
and onPrimary
when rendering the OddUi content.
What’s the best way of doing this?
MaterialTheme’s colors are mutableStateOf
, so do i write
Button1()
MaterialTheme.primary = somethingElse
MaterialTheme.Colors.onPrimary = somethingElse
OddUi()
// restore the two colors
Button2
This feels odd
or would i write
Button1()
CompositionLocalProvider(LocalColors provides MaterialTheme.colors.copy(primary = ..., onPrimary = ...) {
OddUi()
}
Button2
With this though, localColors is internal, so i can’t override it, right?
Is there a third option?Chris Sinco [G]
12/15/2021, 1:32 AMMaterialTheme(
colors = MaterialTheme.colors.copy(primary = ...)
) {
OddUi()
}
@Composable
fun OddUi() {
OddUiTheme {
...
}
}
@Composable
private fun OddUiTheme(
content: @Composable () -> Unit
) {
MaterialTheme(
colors = ...,
typography = ...,
...,
) {
content()
}
}
bbade_
12/15/2021, 2:06 AMColors
be mutableStates? Rather than having the Colors
class be immutable?Chris Sinco [G]
12/15/2021, 2:14 AMLouis Pullen-Freilich [G]
12/15/2021, 2:18 AMMaterialTheme
with a different set of colors around the content as Chris mentioned.
MutableState
is used so that if you are animating / changing one color, only components that consume that color recompose, which makes it a lot more efficient to animate colors in a themeRick Regan
12/15/2021, 3:50 PMMutableState
and in fact still am. In Material 3 terms, in ColorScheme.kt, functions lightColorScheme
and darkColorScheme
return a new ColorScheme
. Under what conditions are the individual colors then changed within those `ColorScheme`s?Louis Pullen-Freilich [G]
12/15/2021, 4:24 PMMaterialTheme
uses the color schemes provided to update its internal color scheme, by changing each individual color
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]nMain/kotlin/androidx/compose/material3/MaterialTheme.kt;l=66Rick Regan
12/15/2021, 4:30 PMExtendedColorScheme
class on ColorScheme
. I made my colors mutableStateOf
as well with a TBD to understand why. Now I think that I don't need to make them mutable 🙂.Louis Pullen-Freilich [G]
12/15/2021, 4:59 PMCompositionLocal
with a simple class of immutable colors