@itcase/icons
v1.2.29
Published
- The `react-native-svg` library is needed to handle SVG files in React Native. If you haven’t installed it yet, follow these steps: https://github.com/software-mansion/react-native-svg
Readme
How to Integrate and Use Icons in React Native Project
1. Install Dependencies
- The
react-native-svglibrary is needed to handle SVG files in React Native. If you haven’t installed it yet, follow these steps: https://github.com/software-mansion/react-native-svg
npm install @itcase/icons @itcase/react-native-ui- Сonfigure
metroconfiguration to support packages with differentexports(take configuration from other projects).
2. Using the Icon Component
- MyIcon.tsx
import { icons24 } from '@itcase/icons/default/svg'
import { Icon } from '@itcase/react-native-ui'
import { ISvgComponent } from '../interfaces/app.interfaces'
const MyIcon = () => {
return (
<Icon
SVGIcon={icons24.General.Dot as unknown as SvgComponent}
/>
);
}The SVG icon is a string (file path or inline SVG), the react-native-svg library converts it to a component, so we cast it to type SvgComponent.
3. Project Structure
src/
├── components/
│ └── MyIcon.tsx
├── interfaces/
│ └── app.interfaces.ts
├── types/
│ └── types.d.ts
└── App.tsx4. Defining Custom SVG Component Type
- app.interfaces.ts
import React from 'react'
import { SvgProps } from 'react-native-svg'
export interface SvgComponent extends React.FC<SvgProps> {}- types.d.ts
declare module '*.svg' {
import React from 'react'
import { SvgProps } from 'react-native-svg'
const content: React.FC<SvgProps>
export default content
}