Until a <Text> sets fontFamily, Android draws it in Roboto and iOS in SF Pro. To ship your own typeface on both platforms, the expo-font config plugin copies the font files into the native Android and iOS projects at build time, so the font is ready the moment the app starts and no loading code runs first. The two platforms don't agree on the name you pass to fontFamily, though, and the font only reaches a build you make yourself.
Key terms
- expo-font config plugin: the
expo-fontentry in thepluginsarray of the app config, which embeds font files in the project's native code at build time. - Font family name: the name a
<Text>style passes infontFamilyto select a font the app has loaded or embedded. - PostScript name: a unique identifier stored in a font file, following Adobe's PostScript standard, that operating systems and apps use to refer to the font. It is different from the font's display name.
Fonts that ship inside the binary
On Android and iOS the plugin is the recommended way to add fonts. Embedding at build time is more efficient than loading the same files at runtime with useFonts or loadAsync. The fonts are available as soon as the app starts on a device, you write no code to load them asynchronously, and every device that installs the app has them because they are bundled in it.
Formats differ by platform. TTF and OTF files embed on both Android and iOS, and WOFF and WOFF2 embed on iOS only.
The package installs with npx expo install expo-font. The SDK 58 default template already lists expo-font in its dependencies, so a project created from it has the package before you add anything.
The fonts, android and ios lists
The plugin entry takes three optional properties, fonts, android and ios, and each one holds an array of font definitions. Every path is relative to the project root. Files in the top-level fonts array are embedded on both platforms. ios.fonts adds files for iOS only and accepts file paths only. android.fonts adds files for Android only and accepts file paths or objects. A path to a directory includes every .ttf, .otf, .woff and .woff2 file inside it.
The Halcyon app.json below embeds two cuts of a typeface, a regular and a bold, from the project's assets/fonts folder. Both go in the top-level list, so both platforms get them from one entry.
Nothing else in the config changes, and no code has to load these files before text can use them. Each file becomes a font of its own, with a name that <Text> passes in fontFamily.
What goes in fontFamily
With a plain list of file paths, each platform names the font its own way:
- On Android, the file name without its extension becomes the font family name, so
./assets/fonts/Halcyon-Bold.ttfis used asfontFamily: 'Halcyon-Bold'. - On iOS, the font family name is always read from the font file itself, and it may not match the file name.
Name each file after the font's PostScript name and the family name stays consistent on both platforms. When renaming isn't an option, for example a file from a package whose name differs from the font's PostScript name, pick the name per platform: the file name on Android and the PostScript name on iOS. The ScreenTitle component below does this with Platform.select, for a file called Halcyon_700Bold.ttf whose PostScript name is Halcyon-Bold.
To check which names the app ended up with, getLoadedFonts() from expo-font returns the loaded font names synchronously, and the list includes fonts embedded with the config plugin.
android.fonts also takes objects. In that form you write the fontFamily yourself, with a weight and an optional style that defaults to "normal", and the plugin embeds the files as native XML font resources. Give it the font's Family Name, which the Font Book app on macOS or fontdrop.info shows. The object form comes back when one family needs several weights.
Development builds and Expo Go
The plugin method doesn't work in Expo Go, because it requires a development build. Expo Go is a pre-built native app that can't be changed after you install it, while the plugin works by changing the native project. After you add or change fonts in the plugin, create a new development build and install it on your device, Android Emulator or iOS Simulator before you use the font.
Config plugins also run only on Android and iOS. A web build gets nothing from this entry, and on web the fonts have to be loaded with useFonts instead.
Files Android skips
Android reads TrueType (.ttf) and OpenType (.otf) files only. From a list of file paths, the plugin copies only .ttf and .otf files into the Android project and skips the rest, so a WOFF2 file in the top-level fonts array reaches iOS and never reaches Android. In the object form the plugin is stricter: a path to any other format stops the build with an error saying the file is one "Android cannot load" and that "Android reads TrueType (.ttf) and OpenType (.otf) files only".
Code Examples
{
"expo": {
"name": "Halcyon",
"slug": "halcyon",
"plugins": [
[
"expo-font",
{
"fonts": [
"./assets/fonts/Halcyon-Regular.ttf",
"./assets/fonts/Halcyon-Bold.ttf"
]
}
]
]
}
}import { Platform, StyleSheet, Text } from 'react-native';
const styles = StyleSheet.create({
title: {
// Android: the file name without its extension.
// iOS: the name read from the font file.
fontFamily: Platform.select({ android: 'Halcyon_700Bold', ios: 'Halcyon-Bold' }),
fontSize: 28,
},
});
export function ScreenTitle({ children }: { children: string }) {
return <Text style={styles.title}>{children}</Text>;
}