From 01f275b34b4af893f2bf79bdb764e8d6501f5c19 Mon Sep 17 00:00:00 2001 From: Luke Walczak Date: Wed, 27 Apr 2022 14:42:37 +0200 Subject: [PATCH] fix: fix font weights for Android (#3165) Co-authored-by: Daniel Szczepanik --- src/components/Typography/AnimatedText.tsx | 4 +++- src/components/Typography/Text.tsx | 4 +++- src/styles/themes/v3/tokens.tsx | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/Typography/AnimatedText.tsx b/src/components/Typography/AnimatedText.tsx index 6c0a1f4171..84b69c53de 100644 --- a/src/components/Typography/AnimatedText.tsx +++ b/src/components/Typography/AnimatedText.tsx @@ -5,6 +5,7 @@ import { I18nManager, StyleProp, StyleSheet, + Platform, } from 'react-native'; import { withTheme } from '../../core/theming'; import { Font, MD3TypescaleKey, Theme } from '../../types'; @@ -43,12 +44,13 @@ function AnimatedText({ style, theme, variant, ...rest }: Props) { if (theme.isV3 && variant) { const stylesByVariant = Object.keys(MD3TypescaleKey).reduce( (acc, key) => { - const { size, weight, lineHeight, tracking } = + const { size, weight, lineHeight, tracking, font } = theme.typescale[key as keyof typeof MD3TypescaleKey]; return { ...acc, [key]: { + ...(Platform.OS === 'android' && { fontFamily: font }), fontSize: size, fontWeight: weight, lineHeight: lineHeight, diff --git a/src/components/Typography/Text.tsx b/src/components/Typography/Text.tsx index e113a0fc1e..8a562bb156 100644 --- a/src/components/Typography/Text.tsx +++ b/src/components/Typography/Text.tsx @@ -5,6 +5,7 @@ import { StyleProp, StyleSheet, I18nManager, + Platform, } from 'react-native'; import { useTheme } from '../../core/theming'; import { Font, MD3TypescaleKey, ThemeProp } from '../../types'; @@ -89,12 +90,13 @@ const Text: React.ForwardRefRenderFunction<{}, Props> = ( if (theme.isV3 && variant) { const stylesByVariant = Object.keys(MD3TypescaleKey).reduce( (acc, key) => { - const { size, weight, lineHeight, tracking } = + const { size, weight, lineHeight, tracking, font } = theme.typescale[key as keyof typeof MD3TypescaleKey]; return { ...acc, [key]: { + ...(Platform.OS === 'android' && { fontFamily: font }), fontSize: size, fontWeight: weight, lineHeight: lineHeight, diff --git a/src/styles/themes/v3/tokens.tsx b/src/styles/themes/v3/tokens.tsx index c8e05bb4e6..fa3252d042 100644 --- a/src/styles/themes/v3/tokens.tsx +++ b/src/styles/themes/v3/tokens.tsx @@ -83,10 +83,10 @@ const ref = { }, typeface: { - brandRegular: 'Roboto Regular', + brandRegular: 'sans-serif', weightRegular: '400' as Font['fontWeight'], - plainMedium: 'Roboto Medium', + plainMedium: 'sans-serif-medium', weightMedium: '500' as Font['fontWeight'], },