From 30461fa68653199b23fca393be914138c448060d Mon Sep 17 00:00:00 2001 From: Aidan Grabe Date: Tue, 20 Dec 2022 16:30:14 +0000 Subject: [PATCH] Android: Fix fontFamily in XML typography --- .../src/main/res/values/typography.xml | 30 +++++++++---------- formats/androidTypography.js | 17 ++++++++++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/android/styledictionary/teamwork-design-system/src/main/res/values/typography.xml b/android/styledictionary/teamwork-design-system/src/main/res/values/typography.xml index 07a1feb..0a7fb74 100644 --- a/android/styledictionary/teamwork-design-system/src/main/res/values/typography.xml +++ b/android/styledictionary/teamwork-design-system/src/main/res/values/typography.xml @@ -14,7 +14,7 @@ textDecoration => none --> `; } +function getFontFamilyTag(token) { + const fontFamilyValue = getFontFamilyValue(token.value.fontFamily, token.value.fontWeight); + if (fontFamilyValue == null) { + return ""; // this is the default font, it's included in the system + } + return `${fontFamilyValue}` +} + +function getFontFamilyValue(fontFamily, fontWeight) { + if (fontFamily == "Roboto") { + return null; // this is the default font, it's included in the system + } + return `@font/${fontFamily.toLowerCase()}_${fontWeight.toLowerCase()}`; +} + function calculateLetterSpacing(fontSize, letterSpacing) { if (indexOf(letterSpacing, "%") != -1) { // We treat percentages as em units. Eg: -2% -> -0.02