Naming Font Files
The file name for a font must match the PostScript name of the font for your flows to properly load the custom font on both Android and iOS. This is because in native Android apps, fonts are referenced by their resource name which is the filename1, while in native iOS apps, fonts are referenced by their PostScript name2. On macOS, you can find the PostScript name of a font by opening it with the Font Book app and selecting the Font Info tab.Expo SDK 50 and above
We recommend using the Expo Font config plugin to directly embed your fonts in your native project.Expo SDK 49 and below
For Expo SDK 49 and below, Expo Font only supports runtime font loading which is incompatible with the Userpilot React Native module because these fonts are not configured or registered with the mobile OS making them inaccessible to for usage in your Userpilot flows. The following steps configure a custom post-install script to give the same result as the configuration above.Configuring the Native Projects
For an Android build, the font files need to be copied to the expected directory. For an iOS build, the font files need to be added to the Xcode project3. To do this while maintaining support for the Expo managed workflow and builds with EAS, update your package.json file with aeas-build-post-install hook4 that utilizes two custom scripts:
Note: these scripts assume your font files are located inassets/fontsin your expo project. If this is not the case, update the paths in the scripts (cp ./<path>/*.ttf "$_"andDir['<path>/*.ttf']).
Registering Custom fonts with iOS
After adding the font file to your project, you need to let iOS know about the font. This is done by adding a keyUIAppFonts to the iOS projects Info.plist. The value is an array value with the name of the font file as an item of the array. Be sure to include the file extension as part of the name.
To set the Info.plist value in your Expo project, add an array of your font file names in your app.json at expo.ios.infoPlist.UIAppFonts:
Summary
Your project should look like this:Footnotes
- “The resource name, which is either the filename excluding the extension…” https://developer.android.com/guide/topics/resources/providing-resources ↩
-
“When retrieving the font with
custom(_:size:), match the name of the font with the font’s PostScript name.” https://developer.apple.com/documentation/swiftui/applying-custom-fonts-to-text/#Apply-a-font-supporting-dynamic-sizing ↩ - Refer to https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app ↩
- Refer to https://docs.expo.dev/build-reference/npm-hooks/ ↩