Giter VIP home page Giter VIP logo

Comments (7)

ricknout avatar ricknout commented on May 21, 2024 1

I'll take a look 👍

from material-components-android-compose-theme-adapter.

chrisbanes avatar chrisbanes commented on May 21, 2024

Hi 👋

How is the font declared in your app? Is it a <font-family> XML file in res/font? Or a simple TTF like res/font/CustomType.ttf?

Can you also paste in one of your TextAppearances?

Thanks

from material-components-android-compose-theme-adapter.

harry248 avatar harry248 commented on May 21, 2024

We aren't using a custom font. Our theme inherits from Theme.MaterialComponents.DayNight.NoActionBar and we're just overriding the textAppearanceHeadlineX, subtitleX, bodyX, etc. attributes to reference our custom text styles. These all inherit from TextAppearance.AppCompat or a more specific TextAppearance.MaterialComponents.* style. No fontFamily is set, just sizes, spacings etc.

Even something as simple as the following causes the exception:

(Theme file)

<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="textAppearanceHeadline1">@style/TextAppearance</item>
    <item name="textAppearanceHeadline2">@style/MyAppearance</item>
    <item name="textAppearanceHeadline3">@style/MyAppearance</item>
    <item name="textAppearanceHeadline4">@style/MyAppearance</item>
    <item name="textAppearanceHeadline5">@style/MyAppearance</item>
    <item name="textAppearanceHeadline6">@style/MyAppearance</item>
    <item name="textAppearanceSubtitle1">@style/MyAppearance</item>
    <item name="textAppearanceSubtitle2">@style/MyAppearance</item>
    <item name="textAppearanceBody1">@style/MyAppearance</item>
    <item name="textAppearanceBody2">@style/MyAppearance</item>
    <item name="textAppearanceButton">@style/MyAppearance</item>
    <item name="textAppearanceCaption">@style/MyAppearance</item>

(In dedicated text appearance styles file)

<style name="MyAppearance" parent="TextAppearance.AppCompat" />

from material-components-android-compose-theme-adapter.

ricknout avatar ricknout commented on May 21, 2024

I'm able to reproduce this in the sample in this library but only if I use TextAppearance.AppCompat.* as the parent, as you've shown above. The problem doesn't occur for TextAppearance.MaterialComponents.* styles. The AppCompat styles seem to resolve to:

<item name="fontFamily">sans-serif-condensed-light</item>

whereas MDC styles resolve to either sans-serif or sans-serif-medium, which I think is the problem. If I add sans-serif-condensed-light to a custom style that extends from MDC I get the same crash.

It's probably something the library should handle, or perhaps a Compose limitation on condensed fonts. But in the meantime I'd suggest using the MDC styles as parents if possible.

from material-components-android-compose-theme-adapter.

chrisbanes avatar chrisbanes commented on May 21, 2024

Hmmm. So the related code for this is here.

It sounds like even though fontFamily is set to sans-serif-condensed-light , tv.resourceId is still being set to something. This would probably be fixed if we do the string check first, then fall through to creating a FontFamilyWithWeight in the else.

from material-components-android-compose-theme-adapter.

harry248 avatar harry248 commented on May 21, 2024

I'm able to reproduce this in the sample in this library but only if I use TextAppearance.AppCompat.* as the parent, as you've shown above. The problem doesn't occur for TextAppearance.MaterialComponents.* styles. The AppCompat styles seem to resolve to:

<item name="fontFamily">sans-serif-condensed-light</item>

whereas MDC styles resolve to either sans-serif or sans-serif-medium, which I think is the problem. If I add sans-serif-condensed-light to a custom style that extends from MDC I get the same crash.

It's probably something the library should handle, or perhaps a Compose limitation on condensed fonts. But in the meantime I'd suggest using the MDC styles as parents if possible.

Thanks, using only MDC styles works.

from material-components-android-compose-theme-adapter.

chrisbanes avatar chrisbanes commented on May 21, 2024

@ricknout do you want to take this? If not, I can probably do it later in the week

from material-components-android-compose-theme-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.