Is it possible to access `MaterialTheme.colorSchem...
# compose
l
Is it possible to access
MaterialTheme.colorScheme
from non-composable?
Copy code
@Stable
val largeRadialGradient = object : ShaderBrush() {
    override fun createShader(size: Size): Shader {
        val biggerDimension = maxOf(size.height, size.width)
        return RadialGradientShader(
            colors = listOf(
               MaterialTheme.colorScheme.primary,... // access colorScheme here
            ),
            center = size.center,
            radius = biggerDimension,
            colorStops = listOf(
                0f,
                0.5f,
                0.8f,
            ),
        )
    }
}
c
@Lilly if
colorScheme
is a
@Composable
then no
l
Obvious, but the color scheme can be accessed in another way, I guess
v
MaterialTheme gets colorScheme through
Copy code
staticCompositionLocalOf
so you can access it only inisde the tree. But well, the Colour itself is not Composable so If you save it additionally somewhere, you can get if from there
s
Material library does this by defining some tokens, and then has a composable function that maps from those tokens to the actual color https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]944?q=fromToken&ss=androidx%2Fplatform%2Fframeworks%2Fsupport. You might be able to just do the same if you need to do this.
l
Thanks guys. I found
Brush.radialGradient()
which is satisfying too
203 Views