I am trying to set TextStyles by MaterialTheme.typ...
# compose
g
I am trying to set TextStyles by MaterialTheme.typography at init time for a class. Unfortunately, typography is a @Composable function and init cannot be Composable. Any good workarounds for this?
z
Just pass the typography object into your constructor as a parameter
Copy code
val typography = MaterialTheme.typography
val yourClass = remember { YourClass(typography) }
g
It is in the constructor of a class I am trying to setup in init.
It looks like constructors can’t be @Composable either.
z
Yes, init in kotlin is effectively the body of the constructor. Just get whatever data you need out of compose before instantiating your object, and then pass it in (see that code snippet)
g
I worked around it by using my non-compose class that defines the typography. Really doesn’t need to be a compose function.