Adding Icons
Set Up
- Install the following packages:
npx expo install react-native-svg lucide-react-native
- Resolve the className strings into icon styles
Add the iconWithClassName
function in the ~/lib/icons/iconWithClassName.ts
file.
import type { LucideIcon } from 'lucide-react-native';import { cssInterop } from 'nativewind';
export function iconWithClassName(icon: LucideIcon) {cssInterop(icon, { className: { target: 'style', nativeStyleToProp: { color: true, opacity: true, }, },});}
- Create a file for each Icon component
Create Icon Components
Wrap your icon components with iconWithClassName
to add a class name to the icon.
Create a file for each icon in ~/lib/icons/
Wrap your icon components with iconWithClassName
to add a class name to the icon.
First, create a new file in the ~/lib/icons/
directory with the name of the LucideIcon.
Then, in each file:
- Import the Icon from LucideIcon
- Import the
iconWithClassName
function
- Call the
iconWithClassName
function and pass the icon as its argument
- Export the Icon as a named export
Examples
Sun
import { Sun } from 'lucide-react-native'; import { iconWithClassName } from './iconWithClassName'; iconWithClassName(Sun); export { Sun };
MoonStar
import { MoonStar } from 'lucide-react-native'; import { iconWithClassName } from './iconWithClassName'; iconWithClassName(MoonStar); export { MoonStar };