Skip to content

Commit

Permalink
feat: add support for fontStyle (callstack#3778)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Janiczek <[email protected]>
  • Loading branch information
tjaniczek and Tomasz Janiczek authored Mar 27, 2023
1 parent d353ee4 commit 084c619
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/docs/guides/04-fonts.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,26 @@ export default function Main() {
);
}
```


## Variable fonts

Although React Native Paper supports `fontWeight` and `fontStyle` properties, there are multiple limitations to custom
fonts in React Native. Using custom [variable fonts](https://fonts.google.com/knowledge/introducing_type/introducing_variable_fonts)
is especially problematic, with some platforms failing to render variants entirely. To ensure correct typography in your
app, we suggest installing each font variant as a separate file. Below you'll find example on how to set up React Native Paper
theme with custom fonts.
Should you decide to use a variable font anyway, second example will show you how to test if the font is rendered correctly in React Native on all platforms.
<details>
<summary>Variable fonts examples</summary>
<ul>
<li>
<a href="https://snack.expo.dev/@react-native-paper/font-styles-variants">How to apply custom fonts with variants</a>
</li>
<li>
<a href="https://snack.expo.dev/@react-native-paper/typography-tester">How to test variable fonts in React Native</a>
</li>
</ul>
</details>
15 changes: 15 additions & 0 deletions src/styles/__tests__/fonts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,14 @@ describe('configureFonts', () => {
bodyLarge: {
fontFamily: 'NotoSans',
fontSize: 18,
fontStyle: 'italic',
},
headlineMedium: {
fontSize: 30,
},
bodySmall: {
fontStyle: 'italic',
},
},
})
).toEqual({
Expand All @@ -219,6 +223,7 @@ describe('configureFonts', () => {
fontFamily: 'NotoSans',
letterSpacing: 0.15,
fontWeight: '400',
fontStyle: 'italic',
lineHeight: 24,
fontSize: 18,
},
Expand All @@ -229,6 +234,14 @@ describe('configureFonts', () => {
lineHeight: 36,
fontSize: 30,
},
bodySmall: {
fontFamily: 'System',
fontWeight: '400',
fontStyle: 'italic',
letterSpacing: 0.4,
lineHeight: 16,
fontSize: 12,
},
});
});

Expand All @@ -240,6 +253,7 @@ describe('configureFonts', () => {
fontFamily: 'NotoSans',
letterSpacing: 0,
fontWeight: '400',
fontStyle: 'italic',
lineHeight: 64,
fontSize: 57,
},
Expand All @@ -251,6 +265,7 @@ describe('configureFonts', () => {
fontFamily: 'NotoSans',
letterSpacing: 0,
fontWeight: '400',
fontStyle: 'italic',
lineHeight: 64,
fontSize: 57,
},
Expand Down
2 changes: 2 additions & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type Font = {
| '700'
| '800'
| '900';
fontStyle?: 'normal' | 'italic' | undefined;
};

export type Fonts = {
Expand Down Expand Up @@ -169,6 +170,7 @@ export type MD3Type = {
fontWeight: Font['fontWeight'];
lineHeight: number;
fontSize: number;
fontStyle?: Font['fontStyle'];
};

export type MD3Typescale =
Expand Down

0 comments on commit 084c619

Please sign in to comment.