@@ -6,8 +6,6 @@ There’s many different ways to use icons and icon sets in Aetherspace. Here’
66→ SSR support, fast & easy, no layout shift on web, limited options
77- Custom SVG components using ` react-native-svg `
88→ SSR support, can [ convert from .svg file] ( https://transform.tools/svg-to-react-native ) , but could be more time-consuming
9- - Third party iconfont libraries, such as ` @expo/vector-icons `
10- → Fast & easy, needs icon font preloaded, layout shift on web, locked out of SWC
119- Image icons through src urls
1210→ Straight forward, easy, not super optimised, fixed colors, layout shift on web
1311
@@ -155,99 +153,6 @@ Downsides of this strategy:
155153- Time consuming: Requires some copy-pasting between transform tools and your code
156154- Therefore, even if it’s most reliable and configurable, also not very fast or scalable
157155
158- ## Using ` @expo/vector-icons `
159-
160- [ Expo Docs: @expo/vector-icons ] ( https://docs.expo.dev/guides/icons/ )
161-
162- > Check which iconset you want to use and how to use them on [ https://icons.expo.fyi/ ] ( https://icons.expo.fyi/ )
163-
164- Benefits of using this strategy:
165-
166- - Fast, choose icons from existing third party icon providers
167- - Most @expo/vector-icons are also compatible with the web
168-
169- Downsides of using icon fonts under the hood:
170-
171- - You’ll need to preload your icon font somehow, easy on mobile but harder on web
172- - Loading flicker, meaning you might not see the icon immediately if the icon font isn’t loaded yet
173- - Cannot use Next.js’s SWC compiler when using any of the @expo/vector-icons (no loader for importing .ttf files)
174-
175- Example usage:
176-
177- ``` tsx
178- import { AntDesign } from ' @expo/vector-icons'
179-
180- <AntDesign
181- name = " caretup"
182- size = { 24 }
183- color = " #333333"
184- />
185- ```
186-
187- Example preloading of icon font on mobile:
188-
189- ` /features/app-core/hooks/useLoadFonts.ts `
190-
191- ``` tsx
192- ' use client'
193- import { useFonts } from ' expo-font'
194- import { /* Google Fonts */ } from ' @expo-google-fonts/roboto'
195-
196- /* --- useLoadFonts() -------------------------------------------------------------------------- */
197-
198- const useLoadFonts = () => {
199- const fontsToLoad = {
200- // - Google Fonts -
201- /* ... */
202- // - Icon Fonts -
203- AntDesign: require (' @expo/vector-icons/build/vendor/react-native-vector-icons/Fonts/AntDesign.ttf' ),
204- // -!- important: always double check this path (^) for your icon fonts
205- }
206-
207- const [fontsLoaded, fontsError] = useFonts (fontsToLoad )
208-
209- if (fontsError ) console .error (' fontErrors:' , fontsLoaded )
210-
211- // -- Return --
212-
213- return fontsLoaded // <- Keep splash screen open until this is true
214- }
215-
216- /* --- Exports --------------------------------------------------------------------------------- */
217-
218- export default useLoadFonts
219- ```
220-
221- Example usage with ` <AetherIcon/> `
222-
223- ` /packages/{workspace-folder}/icons/registry.tsx `
224-
225- ``` tsx
226- import React from ' react'
227- import { registerIconRenderer } from ' aetherspace/utils'
228- import { AntDesign } from ' @expo/vector-icons'
229- import { ComponentProps } from ' react'
230-
231- /** --- iconRegistry --------------------------------------------------------------------------- */
232- /** -i- Register any icons by preferred AetherIcon "name" key */
233- export const iconRegistry = {
234- // Register any icons from e.g. AntDesign you want by
235- // registering them by strings 👇 array (readonly) + render function
236- ... registerIconRenderer ([' caretup' ] as const , ({ name , size , fill , ... restIconProps }) => (
237- <AntDesign
238- name = { name as ComponentProps <typeof AntDesign >[' name' ]}
239- size = { size }
240- color = { fill }
241- { ... restIconProps }
242- />
243- )),
244- } as const // <-- Readonly is important here for accurate type hints
245- ```
246-
247- ``` tsx
248- <AetherIcon name = " caretup" size = { 24 } fill = " #333333" />
249- ```
250-
251156## Using ` AetherImage ` with ` .svg ` files
252157
253158> Using ` AetherImage ` with ` .svg ` files might be the most bundle size friendly way of using SVGs in your app. Since it will always result in only using the SVGs that you actually use in your app.
0 commit comments