Open itsezc opened 3 years ago
For reference:
https://github.com/ForetagInc/Encora/tree/master/components/Icon https://github.com/ForetagInc/Encora/blob/master/util/generate-remix-glyphs.ts
A quick / untested approach to solving this problem, but I would rather prefer that RemixIcon ships with the character map.
Any update on this? It would be really helpful
You could generate the glyph map at build time. See https://docs.expo.dev/versions/latest/config/metro/#virtual-modules
npm install --save-dev entities
tsconfig.json
{
"compilerOptions": {
"paths": {
"virtual:*": ["node_modules/.cache/virtual/*"]
}
}
}
metro.config.js
const path = require('path');
const fs = require('fs');
const { decodeXML } = require('entities');
const { getDefaultConfig } = require('expo/metro-config');
// Generate glyph map for remixicon
const nodeModules = path.resolve(__dirname, 'node_modules');
const glyphData = JSON.parse(
fs.readFileSync(
path.join(nodeModules, 'remixicon/fonts/remixicon.glyph.json'),
),
);
const glyphMap = {};
for (const [name, value] of Object.entries(glyphData)) {
glyphMap[name] = decodeXML(value.unicode);
}
const moduleName = 'remixicon-glyph-map';
const modulePath = path.join(nodeModules, `.cache/virtual/${moduleName}.ts`);
fs.mkdirSync(path.dirname(modulePath), { recursive: true });
fs.writeFileSync(modulePath, 'export default ' + JSON.stringify(glyphMap));
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
module.exports = config;
src/components/Remix.tsx
import createIconSet from '@expo/vector-icons/createIconSet';
import { Asset } from 'expo-asset';
import fontAssetId from 'remixicon/fonts/remixicon.ttf';
import glyphMap from 'virtual:remixicon-glyph-map';
export type IconName = keyof typeof glyphMap;
const asset = Asset.fromModule(fontAssetId);
export const Remix = createIconSet(glyphMap, 'remixicon', asset.uri);
Currently one would have to use separate tooling to generate glyph maps for Remix Icons on React Native (Expo).
The current
remixicon.glyph.json
is not directly compatible with Expos glyph map structure.Current:
The required glyph map structure for expo:
It would be useful if from next release a new file named
remixicon.expo.json
could be appended in this format. This would make easy for one to use Remix Icons with Expo.For reference: https://docs.expo.io/guides/icons/