Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android support for fonts & textCase via textAllCaps #1331

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

niggeulimann
Copy link

As discussed earlier in the this PR includes two things:

  1. it resolves a token of type fontFamily to an android-ressource entry like
    <item name="typography_body_font_family" type="font">@font/comic_sans_regular</item>

❗️to fully support this, i also use the following transform, which is not included yet

export const androidFontFamilyTransform = {
    type: "value",
    name: "android/androidFontFamilyTransform",
    transitive: true,
    filter: (token) =>
      token.attributes.item === "fontFamily" ||
      token.attributes.subitem === "fontFamily",
    transform: (token) => {
      return "@font/"+token.value;
    }
  };

Usage: the value can be used with https://developer.android.com/reference/android/widget/TextView#attr_android:fontFamily - please ensure that the font-file has the same name

  1. it resolves a token of type textCase to a bool android ressource like this:
    <bool name="typography_body_text_case">false</bool>
    ❗️this also needs a transform:
export const androidTextCaseTransform = {
    type: "value",
    name: "android/textCaseAsBool",
    transitive: true,
    filter: (token) => {
      return token.type === "textCase";
    },
    transform: (token) => {
       return token.value === "uppercase" ? "true" : "false";
    }
  };

Usage: the generated resource can be used with https://developer.android.com/reference/android/widget/TextView#attr_android:textAllCaps

From our point of view, this would be a big improvement.

niggeulimann and others added 4 commits September 6, 2024 12:02
font_families are transformed to
<item name="<token_name>" type="font">comic_sans_regular</item>

text_cases as a bool like this:
<bool name="<token_name>">false|true</bool>
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-1331.d16eby4ekpss5y.amplifyapp.com

@jorenbroekema
Copy link
Collaborator

Thanks for contributing this, I think it makes sense to add both transforms you mentioned and then also have them added to the android transformGroup. The "true" and "false" values can be just true and falseand the filter can check for the$type/typeinstead of theattributes.item/attributes.subitem`.

I think we need to discuss with @dbanksdesign whether we want to create a new format/transformGroup for these improvements or whether we consider this bugfixes that should be added in a minor patch. Technically speaking changing the format / token value transforms within a transformGroup are breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants