expo-font
Version:
Load fonts at runtime and use them in React Native components.
29 lines (25 loc) • 968 B
text/typescript
import { requireNativeModule } from 'expo-modules-core';
import type { ServerFontResourceDescriptor, UnloadFontOptions } from './Font.types';
export type ExpoFontLoaderModule = {
getLoadedFonts: () => string[];
loadAsync: (fontFamilyName: string, localUriOrWebAsset: any) => Promise<void>;
// the following methods are only available on web
unloadAllAsync?: () => Promise<void>;
unloadAsync?: (fontFamilyName: string, options?: UnloadFontOptions) => Promise<void>;
isLoaded?: (fontFamilyName: string, options?: UnloadFontOptions) => boolean;
getServerResources?: () => string[];
getServerResourceDescriptors?: () => ServerFontResourceDescriptor[];
};
const m: ExpoFontLoaderModule =
typeof window === 'undefined'
? // React server mock
{
getLoadedFonts() {
return [];
},
loadAsync() {
return Promise.resolve();
},
}
: requireNativeModule('ExpoFontLoader');
export default m;