Little hack that I made
See original GitHub issueHey there. I just made this little code so I can keep all my fonts in a single file, and easily access and use them with Intellisense. I couldn’t find a way to avoid the duplicate writing of the font in import and in the useFontsArg (as this lib also requires). However, still a nice hack!
// A 'fonts.ts' file
import {
NotoSans_400Regular,
NotoSans_700Bold
} from '@expo-google-fonts/noto-sans';
import {
Roboto_400Regular,
Roboto_500Medium,
Roboto_700Bold
} from '@expo-google-fonts/roboto';
export { useFonts } from 'expo-font';
export const useFontsArg = {
NotoSans_400Regular,
NotoSans_700Bold,
Roboto_400Regular,
Roboto_500Medium,
Roboto_700Bold
};
type PropsToString<Obj> = {
[K in keyof Obj]: string
}
export const fonts = { ...useFontsArg } as unknown as PropsToString<typeof useFontsArg>;
Object.keys(fonts).forEach((e: any) => (fonts as any)[e] = e );
// App.tsx
export default function App() {
const [fontsLoaded] = useFonts(useFontsArg);
if (!fontsLoaded)
return <AppLoading/>;
return <Text style={{fonts.Roboto_500Medium}}> Hey! </Text>` // Intellisense guides you! Yay!
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
40+ SMART HACKS to fix little problems in your home
... hack 1:40 Cable hack 2:37 Wire hack 3:04 Brick idea 3:57 Howe to find a screw with magnet This video is made...
Read more >7 Small Life Hacks That Make a Big Difference - YouTube
Life hacks are creative ways to make everyday tasks simpler. And for people living with multiple sclerosis (MS), simplicity is key.
Read more >Birth To Death of Four Elements in Real Life by Ha Hack
She tries out little tiny hacks and miniature dollhouse crafts! She also makes money to buy rainbow friends and says yes to dolls...
Read more >Useful LIFE HACKS that Actually Work - YouTube
Useful LIFE HACKS that Actually Work ! Trying out some do it yourself fun, girly life hacks ! ... Little Lia. Little Lia....
Read more >Easiest little hack that makes your tv console look so ... - TikTok
432 Likes, TikTok video from Addie Lee (@addieleeh): "Easiest little hack that makes your tv console look so much cleaner #ikea # hack...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks so much for sharing, @SrBrahma! I’m already using it 💪
The styles prop should be something like this:
style={{ fontFamily: fonts.Roboto_500Medium }}
though 👀The above had some errors. I made the function I said. It’s used like the following:
Source
~I am busy right now but eventually will turn it into a npm package. Or, I think it could be added to this lib or any other related Expo lib.~ Edit: It has been released! https://github.com/SrBrahma/expo-font-loader