Fully typed Icon component for react-native-vector-icons.
-
Install react-native-vector-icons
-
Install this package
yarn add react-native-easy-icon
Follow these steps:
# 1. Install dependencies
yarn add react-native-easy-icon
# 2. Add new icon set to index.tsx > IconSets array
# 3. Generate a typed Icon component by parsing react-native-vector-icons package.
yarn generate
# 4. Build
yarn build
The generation script:
- For each icon set (AntDesign, Zocial, Entypo, etc), find the glyph map file by reading each
./node_modules/react-native-vector-icons/${iconSetName}.js
- Example from Feather.js:
import createIconSet from './lib/create-icon-set'; import glyphMap from './glyphmaps/Feather.json'; // the script gets this path. // ...
- We cannot assume that the glyph map file path is
.../glyphmaps/${iconSetName}.json
because FontAwesome5 is an exception.
- Get list of icon names of each icon set by parsing glyph map files.
- Example from glyphmaps/Feather.json:
{ "activity": 61696, "airplay": 61697, "alert-circle": 61698, //... }
- Generate
${iconSetName}.d.ts
insrc/types/
for each icon set.- Example of Feather.d.ts:
const FeatherIcons = ["activity","airplay","alert-circle",...] type FeatherIcon = (typeof FeatherIcons)[number]
- Generate an Icon component in
src/Icon.tsx
.