Thread
#compose
    d

    dan.the.man

    11 months ago
    Hello, question: I set a custom theme with Typography of my own font
    @Composable
    fun MyTheme(
        content: @Composable () -> Unit
    ) {
        MaterialTheme(
            typography = Typography(appFontFamily),
            content = content
        )
    }
    Using this, it correctly applies the font family if I do a normal text, but as soon as I apply a TextStyle to a
    Text
    , it doesn't apply that default font family anymore
    val displayJumboBold = TextStyle(
            fontSize = 40.sp,
            fontWeight = FontWeight.Bold,
            lineHeight = 48.sp
        )
    I assume this is because the TextStyle defaults to null for font family if I don't explicitly set it, but should it not fall back to the default of the Theme that I've set?
    Chris Sinco [G]

    Chris Sinco [G]

    11 months ago
    Yes, fontFamily is a nullable parameter with a default value of
    null
    - that ends up resolving back to the DefaultFontFamily of the system (in the implementation of TextStyle), and not from the theme. This is intentional since Compose allows you to override styles at that local composition scope, which in this case is
    null
    .
    If you want to override specific TextStyle properties that deviate from the theme typography styles, I’d suggest setting them using their parameter names directly, e.g. fontSize
    d

    dan.the.man

    11 months ago
    It doesn't deviate from the theme's typography style, it defaults back to Roboto, instead of the custom one that I set as
    appFontFamily
    Chris Sinco [G]

    Chris Sinco [G]

    11 months ago
    Right. I assume though you are trying to use
    displayJumboBold
    but you don’t want to change fontFamily?
    d

    dan.the.man

    11 months ago
    Setting the
    Text(style = displayJumboBold)
    ends up changing the font back as if I never set the default.
    Text()
    displays correctly with the
    appFontFamily
    applied
    Yeah, I want
    displayJumboBold
    to not change the font of the
    Text
    it's applied ot
    Chris Sinco [G]

    Chris Sinco [G]

    11 months ago
    I see - I might be missing some details so maybe @Louis Pullen-Freilich [G] can weigh in. But I believe what you are seeing is expected
    l

    Louis Pullen-Freilich [G]

    11 months ago
    The default for the theme is just the default for text styles inside
    Typography
    , there is no way to set a global default font family in this way. Might be easiest to create your own
    Text()
    implementation that sets it if it is missing from the style