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

Use Font XML resources and standardise font usage on native platforms #41115

Merged
merged 33 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6839328
Link assets with Font XML resources
fabioh8010 Apr 26, 2024
36e3972
Remove duplicated fonts
fabioh8010 Apr 26, 2024
a750d10
Refactor all usages of fontFamily
fabioh8010 Apr 26, 2024
4316e5c
Merge branch 'main' into feature/link-assets-v2
fabioh8010 May 7, 2024
a0afca4
Fix styles
fabioh8010 May 7, 2024
0254d54
Fix fonts cross-compatibilities
fabioh8010 May 7, 2024
94ea305
Merge remote-tracking branch 'origin/main' into feature/link-assets-v2
fabioh8010 May 7, 2024
4775ecb
Fix tests
fabioh8010 May 7, 2024
395523c
Merge branch 'main' into feature/link-assets-v2
fabioh8010 May 13, 2024
8ed64e7
Removes unnecessary fontWeight
fabioh8010 May 13, 2024
aae1434
Align web fonts with same naming convention native has
fabioh8010 May 14, 2024
43f3f13
Merge remote-tracking branch 'origin/main' into feature/link-assets-v2
fabioh8010 May 14, 2024
7048e23
Refactor improvements
fabioh8010 May 14, 2024
67f705d
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jun 7, 2024
42accdb
Fix fonts
fabioh8010 Jun 7, 2024
ec4f2f3
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jun 7, 2024
54b70f5
Merge remote-tracking branch 'origin/main' into feature/link-assets-v2
fabioh8010 Jun 9, 2024
95af383
Add doc from font management
fabioh8010 Jun 10, 2024
e9c2f8a
Add comments explaining difference between platform, single and multi…
fabioh8010 Jun 10, 2024
2d66de1
Move fontWeight types to index
fabioh8010 Jun 10, 2024
ec29d02
Merge remote-tracking branch 'origin/main' into feature/link-assets-v2
fabioh8010 Jun 10, 2024
7a6898b
Address review comments
fabioh8010 Jun 10, 2024
f835e54
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jun 28, 2024
135e20b
Fix bold markdown not being applied
fabioh8010 Jun 28, 2024
27b1a59
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jul 1, 2024
f7d9004
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jul 2, 2024
a027ce8
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jul 9, 2024
07397ff
Simplify applyPatches script
fabioh8010 Jul 10, 2024
f3c84a6
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jul 15, 2024
89a8783
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jul 19, 2024
98735ed
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jul 22, 2024
93d895b
Fix storybook theme.ts file
fabioh8010 Jul 22, 2024
f7a5206
Merge branch 'main' into feature/link-assets-v2
fabioh8010 Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.expensify.chat

import com.facebook.react.common.assets.ReactFontManager

import android.app.ActivityManager
import android.content.res.Configuration
import android.database.CursorWindow
Expand Down Expand Up @@ -42,6 +44,9 @@ class MainApplication : MultiDexApplication(), ReactApplication {

override fun onCreate() {
super.onCreate()
ReactFontManager.getInstance().addCustomFont(this, "Expensify New Kansas", R.font.expensify_new_kansas)
ReactFontManager.getInstance().addCustomFont(this, "Expensify Neue", R.font.expensify_neue)
ReactFontManager.getInstance().addCustomFont(this, "Expensify Mono", R.font.expensify_mono)

RNPerformance.getInstance().mark("appCreationStart", false);

Expand Down
5 changes: 5 additions & 0 deletions android/app/src/main/res/font/expensify_mono.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<font app:fontStyle="normal" app:fontWeight="400" app:font="@font/expensifymono_regular"/>
<font app:fontStyle="normal" app:fontWeight="700" app:font="@font/expensifymono_bold"/>
</font-family>
7 changes: 7 additions & 0 deletions android/app/src/main/res/font/expensify_neue.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<font app:fontStyle="italic" app:fontWeight="400" app:font="@font/expensifyneue_italic"/>
<font app:fontStyle="normal" app:fontWeight="400" app:font="@font/expensifyneue_regular"/>
<font app:fontStyle="italic" app:fontWeight="700" app:font="@font/expensifyneue_bolditalic"/>
<font app:fontStyle="normal" app:fontWeight="700" app:font="@font/expensifyneue_bold"/>
</font-family>
5 changes: 5 additions & 0 deletions android/app/src/main/res/font/expensify_new_kansas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<font app:fontStyle="italic" app:fontWeight="500" app:font="@font/expensifynewkansas_mediumitalic"/>
<font app:fontStyle="normal" app:fontWeight="500" app:font="@font/expensifynewkansas_medium"/>
</font-family>
Binary file removed android/app/src/main/res/font/expneuebold.otf
Binary file not shown.
Binary file removed android/app/src/main/res/font/expneueregular.otf
Binary file not shown.
8 changes: 4 additions & 4 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<style name="TextViewSpinnerDropDownItem" parent="Widget.AppCompat.DropDownItem.Spinner">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">@dimen/spinner_font_size</item>
<item name="android:fontFamily">@font/expneuebold</item>
<item name="android:fontFamily">@font/expensifyneue_bold</item>
</style>

<!-- Theme used by the Alert dialog -->
Expand All @@ -37,15 +37,15 @@
</style>

<style name="AlertTextAppearanceSmall" parent="TextAppearance.AppCompat.Small">
<item name="android:fontFamily">@font/expneueregular</item>
<item name="android:fontFamily">@font/expensifyneue_regular</item>
</style>

<style name="AlertTextAppearanceMedium" parent="TextAppearance.AppCompat.Medium">
<item name="android:fontFamily">@font/expneueregular</item>
<item name="android:fontFamily">@font/expensifyneue_regular</item>
</style>

<style name="AlertTextAppearanceLarge" parent="TextAppearance.AppCompat.Large">
<item name="android:fontFamily">@font/expneuebold</item>
<item name="android:fontFamily">@font/expensifyneue_bold</item>
</style>

<style name="Theme.SplashScreen.Common" parent="Theme.AppCompat.NoActionBar">
Expand Down
2 changes: 1 addition & 1 deletion android/link-assets-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"migIndex": 1,
"migIndex": 2,
"data": [
{
"path": "assets/fonts/native/ExpensifyMono-Bold.otf",
Expand Down
2 changes: 1 addition & 1 deletion ios/link-assets-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"migIndex": 1,
"migIndex": 2,
"data": [
{
"path": "assets/fonts/native/ExpensifyMono-Bold.otf",
Expand Down
2 changes: 1 addition & 1 deletion src/components/EnvironmentBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function EnvironmentBadge() {
error={error}
text={text}
badgeStyles={[styles.alignSelfStart, styles.headerEnvBadge, styles.environmentBadge, badgeEnviromentStyle]}
textStyles={[styles.headerEnvBadgeText, {fontWeight: '700'}]}
textStyles={styles.headerEnvBadgeText}
environment={environment}
pressable
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function BaseHTMLEngineProvider({textSelectable = false, children, enableExperim
baseStyle={styles.webViewStyles.baseFontStyle}
tagsStyles={styles.webViewStyles.tagStyles}
enableCSSInlineProcessing={false}
systemFonts={Object.values(FontUtils.fontFamily.single)}
systemFonts={Object.values(FontUtils.fontFamily.single).map((font) => font.fontFamily)}
htmlParserOptions={{
recognizeSelfClosing: true,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {CustomRendererProps, TPhrasing, TText} from 'react-native-render-ht
import * as HTMLEngineUtils from '@components/HTMLEngineProvider/htmlEngineUtils';
import InlineCodeBlock from '@components/InlineCodeBlock';
import useStyleUtils from '@hooks/useStyleUtils';
import FontUtils from '@styles/utils/FontUtils';

type CodeRendererProps = CustomRendererProps<TText | TPhrasing> & {
/** Key of the element */
Expand All @@ -17,10 +18,7 @@ function CodeRenderer({TDefaultRenderer, key, style, ...defaultRendererProps}: C
const {boxModelStyle, otherStyle: textStyle} = splitBoxModelStyle(style ?? {});

/** Get the default fontFamily variant */
const font = StyleUtils.getFontFamilyMonospace({
fontStyle: undefined,
fontWeight: undefined,
});
const font = FontUtils.fontFamily.platform.MONOSPACE.fontFamily;

// Determine the font size for the code based on whether it's inside an H1 element.
const isInsideH1 = HTMLEngineUtils.isChildOfH1(defaultRendererProps.tnode);
Expand Down
8 changes: 4 additions & 4 deletions src/components/Onfido/BaseOnfidoWeb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ function initializeOnfido({sdkToken, onSuccess, onError, onUserExit, preferredLo
token: sdkToken,
containerId: CONST.ONFIDO.CONTAINER_ID,
customUI: {
fontFamilyTitle: `${FontUtils.fontFamily.platform.EXP_NEUE}, -apple-system, serif`,
fontFamilySubtitle: `${FontUtils.fontFamily.platform.EXP_NEUE}, -apple-system, serif`,
fontFamilyBody: `${FontUtils.fontFamily.platform.EXP_NEUE}, -apple-system, serif`,
fontFamilyTitle: `${FontUtils.fontFamily.platform.EXP_NEUE.fontFamily}, -apple-system, serif`,
fontFamilySubtitle: `${FontUtils.fontFamily.platform.EXP_NEUE.fontFamily}, -apple-system, serif`,
fontFamilyBody: `${FontUtils.fontFamily.platform.EXP_NEUE.fontFamily}, -apple-system, serif`,
fontSizeTitle: `${variables.fontSizeLarge}px`,
fontWeightTitle: Number(FontUtils.fontWeight.bold),
fontWeightSubtitle: 400,
fontWeightSubtitle: Number(FontUtils.fontWeight.normal),
fontSizeSubtitle: `${variables.fontSizeNormal}px`,
colorContentTitle: theme.text,
colorContentSubtitle: theme.text,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Text({color, fontSize = variables.fontSizeNormal, textAlign = 'left', c
color: color ?? theme.text,
fontSize,
textAlign,
fontFamily: FontUtils.fontFamily.platform[family],
...FontUtils.fontFamily.platform[family],
...StyleSheet.flatten(style),
};

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useMarkdownStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ function useMarkdownStyle(message: string | null = null): MarkdownStyle {
paddingLeft: 6,
},
code: {
fontFamily: FontUtils.fontFamily.platform.MONOSPACE,
...FontUtils.fontFamily.platform.MONOSPACE,
fontSize: 13, // TODO: should be 15 if inside h1, see StyleUtils.getCodeFontSize
color: theme.text,
backgroundColor: 'transparent',
},
pre: {
fontFamily: FontUtils.fontFamily.platform.MONOSPACE,
...FontUtils.fontFamily.platform.MONOSPACE,
fontSize: 13,
color: theme.text,
backgroundColor: 'transparent',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function HeaderView({
}
return (
<>
<Text style={[styles.sidebarLinkText, styles.textLabelSupporting, styles.fontWeightNormal]}> {translate('threads.in')} </Text>
<Text style={[styles.sidebarLinkText, styles.textLabelSupporting]}> {translate('threads.in')} </Text>
<Text style={[styles.sidebarLinkText, styles.textLabelSupporting, styles.textStrong]}>{policyName}</Text>
</>
);
Expand Down
Loading
Loading