Advice please how to correctly establish typograph...
# compose
i
Advice please how to correctly establish typography in compose project for day-night theme if i want to use
color
parameter in each
TextStyle
? I see next options 1. use resources and separate colors by folders. Good for theming, because all happens authomatically, but i don’t understand yet how to create Color from resource without @Composable
colorResource
2. use colors preset from kotlin code. In this case all variants that i can imagine leads multiple if-else cases Please, say, maybe i somehow skipped some obvious solution?
m
you can have
darkColors
and
lightColors
set up in your theme and you set colors you want there. later you can call
MaterialTheme.colors
and access colors that you need, they will be day/night specific
you can also use
CompositionLocalProvider
this perhaps leans to custom theming rather than material theming in which case you should utilise `CompositionLocalProvider`s
you should have theme at one place, not scatter colors all over the place
i
If i’ve understood correct you mean assigning text color in place where Text created, but i mean assigning text style color in place where typography created. All i want to do as little work as possible. I want to create one single Typography, color it, and assign it once to material theme for not to set text color each time (exclude cases where text must be another color). I assume that primary color (or whatever color) from material theme will be used as text color by default (under the hood of compose), but theming in app is custom and i not sure that text color and the primary color (or whatever color) will be the same in my design system. I want to text has own default custom color depends on day-night theme and it must assigns when typography is creating (or when day-night theme changing). And i try to found the simplest way to reach that
I assume the best way to achieve my purposes is using of two typographies like an
Copy code
val dayTypography = Typography(...)
val nightTypography = Typography(...)

MaterialTheme(
    colors = if (isSystemInDarkTheme()) DarkColors else LightColors,
    typography = if (isSystemInDarkTheme()) dayTypography else nightTypography,
    shapes = Shapes,
    content = content
)
m
@iamthevoid I completely misunderstood your question