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: force em values to use the X.em format #104

Merged
merged 2 commits into from
Jul 31, 2024

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Jul 31, 2024

There might be a better way to do this, but I couldn't find it.

The issue

src/transforms/kotlin/percentageEm.ts transforms % values into em ones with the format X.em (note the dot is important for Kotlin).

However, when this value is later used in src/transforms/kotlin/typography.ts, it seems like it's re-interpreted by the style dictionary in some way and it returns Xem instead for round values (without the dot). If I return something that can't re reinterpreted (such as 0.em!) it'll be provided as is in typography.ts, without any changes.

The workaround

Always return a value with a decimal place, even if it's .0 for round values. This way the .em is kept, probably because the returned value is not re-interpreted as an em one by style dictionary.

@jmartinesp jmartinesp requested a review from a team as a code owner July 31, 2024 07:05
@jmartinesp jmartinesp force-pushed the fix/android-em-with-round-values branch 3 times, most recently from 02cb61f to 0f15b23 Compare July 31, 2024 07:20
@jmartinesp jmartinesp force-pushed the fix/android-em-with-round-values branch from 0f15b23 to 9909370 Compare July 31, 2024 07:23
Copy link
Member

@pixlwave pixlwave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, looks reasonable to me, but maybe you want to wait for Robin as I have no idea about what might be a better solution :)

@jmartinesp jmartinesp requested a review from robintown July 31, 2024 13:25
@robintown
Copy link
Member

I'm taking a quick look, I'll let you know if I see something better

@robintown
Copy link
Member

This fixes it:

diff --git a/src/configs/getAndroidConfig.ts b/src/configs/getAndroidConfig.ts
index 25e57d0..bfd1db7 100644
--- a/src/configs/getAndroidConfig.ts
+++ b/src/configs/getAndroidConfig.ts
@@ -240,7 +240,6 @@ export function getCommonAndroidConfig(): PlatformConfig {
   return {
     transforms: [
       "camelCaseDecimal",
-      "ts/resolveMath",
       "attribute/cti",
       "kotlin/fontWeight",
       "kotlin/literal",

The reason seems to be that Tokens Studio transforms (which is where ts/resolveMath comes from) started out as a Web-oriented project and is not yet aware of how to format dimensional values for iOS and Android. We're actually early adopters!

In theory we should resolve math expressions even for Android, but in practice we're not using them yet, so this should work for now. If we ever do need them, we could contribute support for Kotlin-style dimensions to the Tokens Studio project.

@jmartinesp
Copy link
Member Author

Yes, I can confirm it works by just removing it. Thanks @robintown !

@jmartinesp jmartinesp merged commit 2af7bb5 into main Jul 31, 2024
3 checks passed
@jmartinesp jmartinesp deleted the fix/android-em-with-round-values branch July 31, 2024 14:04
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.

3 participants