https://kotlinlang.org logo
Title
t

Tolriq

05/24/2022, 2:36 PM
Is there some kind of
Typography(defaultFontFamily = Rubik)
Equivalent for M3 ? Or are we supposed to copy paste all the internal token stuff and maintain them when they evolve ?
s

Stylianos Gakis

05/24/2022, 3:13 PM
I haven’t played with M3 at all, but I know that this is simply a convenience secondary constructor . You can probably define your own that does the exact same thing to avoid having to copy-paste as you said
t

Tolriq

05/24/2022, 3:14 PM
Not for M3 😞 It's all based on internal / private token stuff
s

Stylianos Gakis

05/24/2022, 3:19 PM
Alright, I wonder why that decision was made, maybe there’s good reason for it. But besides that, you can probably still define your own function that takes all the inputs the M3 Typography class needs, plus a defaultFontFamily that does this for you in one place.
t

Tolriq

05/24/2022, 3:21 PM
Yes that means copy all the tokens values and updating them each time those M3 token values are updated. (What I said I'd like to avoid in first post)
s

Stylianos Gakis

05/24/2022, 3:25 PM
Fair enough. I wonder who we could ping in here from Google who works on M3 to explain why that secondary constructor does not exist as it does for M2. If anything, you can make a FeatureRequest in the bug tracker for this functionality. Someone appropriate will definitely take a look at it there. And link it back here so that people who face the same issue can upvote it.
b

Berkeli Alashov

05/25/2022, 6:45 AM
I think you can do it this way:
private val fontFamily = FontFamily(...)
private val defaults = Typography()
val AppTypography = Typography(
    displayLarge = defaults.displayLarge.copy(
        fontFamily = fontFamily,
    ),
    labelSmall = defaults.labelSmall.copy(
        fontFamily = fontFamily,
    ),
    ...
)
❤️ 1
t

Tolriq

05/25/2022, 6:50 AM
Arf of course, thanks a lot. Since it's not data class I did not even thought of checking if they added a copy method ... Shame on me.