Skip to content

Commit 94e26ef

Browse files
committed
feat: add custom microsoft font as the default text font
1 parent 2ea0cd7 commit 94e26ef

File tree

8 files changed

+40
-4
lines changed

8 files changed

+40
-4
lines changed

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@react-navigation/native": "^5.8.1",
1717
"@react-navigation/stack": "^5.11.0",
1818
"expo": "^38.0.0",
19+
"expo-font": "~8.2.1",
1920
"expo-splash-screen": "^0.3.1",
2021
"react": "16.11.0",
2122
"react-dom": "16.11.0",

example/src/App.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
/* eslint-disable global-require */
12
import React from 'react';
2-
3+
import { View } from 'react-native';
34
import { NavigationContainer } from '@react-navigation/native';
5+
import { useFonts } from 'expo-font';
6+
import { Hourglass, fontNames } from 'react95-native';
47

58
import { LocalThemeProvider } from './util/LocalThemeContext';
69
import MainNavigation from './MainNavigation';
710

811
const App = () => {
12+
const [fontLoaded] = useFonts({
13+
[fontNames.normal]: require('./assets/fonts/MS-Sans-Serif.ttf'),
14+
[fontNames.bold]: require('./assets/fonts/MS-Sans-Serif-Bold.ttf'),
15+
});
16+
17+
if (!fontLoaded) {
18+
return (
19+
<View
20+
style={{
21+
flex: 1,
22+
justifyContent: 'center',
23+
alignItems: 'center',
24+
backgroundColor: 'teal',
25+
}}
26+
>
27+
<Hourglass size={60} />
28+
</View>
29+
);
30+
}
31+
932
return (
1033
<LocalThemeProvider>
1134
<NavigationContainer>
12 KB
Binary file not shown.
13.9 KB
Binary file not shown.

example/src/examples/TypographyExample.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const TypographyExample = () => {
1111
<Text>Simple text</Text>
1212
</Panel>
1313
</Container.Section>
14+
<Container.Section title='Bold'>
15+
<Panel>
16+
<Text bold>Bold text</Text>
17+
</Panel>
18+
</Container.Section>
1419
<Container.Section title='Disabled'>
1520
<Panel>
1621
<Text disabled>Disabled</Text>

src/Typography/Text.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { Text as NativeText, StyleProp, TextStyle } from 'react-native';
33

44
import { ThemeContext } from '../common/theming/Theme';
55

6+
export const fontNames = {
7+
normal: 'MS Sans Serif',
8+
bold: 'MS Sans Serif Bold',
9+
};
10+
611
type Props = React.ComponentProps<typeof NativeText> & {
712
bold?: boolean;
813
children: React.ReactNode;
@@ -25,9 +30,11 @@ const Text = ({
2530
if (disabled) {
2631
return theme.text.disabled;
2732
}
33+
2834
if (secondary) {
2935
return theme.text.secondary;
3036
}
37+
3138
return theme.text.default;
3239
};
3340

@@ -36,7 +43,7 @@ const Text = ({
3643
style={[
3744
getTextStyle(),
3845
{
39-
fontWeight: bold ? 'bold' : 'normal',
46+
fontFamily: bold ? fontNames.bold : fontNames.normal,
4047
},
4148
style,
4249
]}

src/Typography/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { default as Text } from './Text';
1+
export { default as Text, fontNames } from './Text';
22
export { default as Anchor } from './Anchor';

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export { default as Button } from './Button';
22
export { default as TextInput } from './TextInput';
33
export { default as Panel } from './Panel';
4-
export { Text, Anchor } from './Typography';
4+
export { Text, Anchor, fontNames } from './Typography';
55
export { default as AppBar } from './AppBar';
66
export { default as Cutout } from './Cutout';
77
export { default as Window } from './Window';

0 commit comments

Comments
 (0)