-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fonts not loading on the web #422
Comments
I fixed it rudimentary by adding this function FontsProvider({ children }: { children: React.ReactNode }) {
if (Platform.OS !== 'web') {
return children;
}
return <WebFontsLoader fallback={<View />}>{children}</WebFontsLoader>;
} function Providers({ children }: { children: React.ReactNode }) {
...
return (
...
<ThemeProvider value={theme}>
<FontsProvider> // <------ Added within the theme so that fallback component has access to it potentially
<APIProvider>
...
</APIProvider>
</FontsProvider>
</ThemeProvider>
...
) |
@joernroeder I haven't tried it yet, but I think adding your font inside +html.tsx would be a good idea. <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cairo:[email protected]&family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet"> |
@yjose that works if you do use fonts from google but i want to serve the same font file in the assets directory used by the native app. Font's may diverge and some custom fonts are simply not available on public repos. see this comment which I linked above. expo/expo#27562 (comment) The solution in that thread and demonstrated above works perfectly. |
@joernroeder I would appreciate it if you could add this solution to the font docs page. |
sure. I can also go ahead and do a PR to add the font provider, we could even make the font a build var. I'll play around and come back. |
Summary:
as you're using a config plugin to add fonts they are not added to the web bundle. see expo/expo#27562 for more info and a potential solution.
The text was updated successfully, but these errors were encountered: