1import { CodedError } from 'expo-modules-core'; 2 3import ExpoFontLoader from './ExpoFontLoader'; 4import { FontSource } from './Font.types'; 5import { getAssetForSource, loadSingleFontAsync } from './FontLoader'; 6 7/** 8 * @returns the server resources that should be statically extracted. 9 * @private 10 */ 11export function getServerResources(): string[] { 12 return ExpoFontLoader.getServerResources(); 13} 14 15/** 16 * @returns clear the server resources from the global scope. 17 * @private 18 */ 19export function resetServerContext() { 20 return ExpoFontLoader.resetServerContext(); 21} 22 23export function registerStaticFont(fontFamily: string, source?: FontSource | null) { 24 // MUST BE A SYNC FUNCTION! 25 if (!source) { 26 throw new CodedError( 27 `ERR_FONT_SOURCE`, 28 `Cannot load null or undefined font source: { "${fontFamily}": ${source} }. Expected asset of type \`FontSource\` for fontFamily of name: "${fontFamily}"` 29 ); 30 } 31 const asset = getAssetForSource(source); 32 33 loadSingleFontAsync(fontFamily, asset); 34} 35