Lucide React Native
为 React Native 应用实现 lucide 图标库。
¥Implementation of the lucide icon library for React Native applications
安装
¥Installation
首先,请确保你已安装 react-native-svg
(版本 12 到 15 之间)。然后,安装软件包:
¥First, ensure that you have react-native-svg
(version between 12 and 15) installed. Then, install the package:
pnpm install lucide-react-native
yarn add lucide-react-native
npm install lucide-react-native
bun add lucide-react-native
如何使用
¥How to use
每个图标都可以作为 React 组件导入。
¥Each icon can be imported as a React component.
示例
¥Example
可以传递其他属性来调整图标:
¥Additional props can be passed to adjust the icon:
import { Camera } from 'lucide-react-native';
// Usage
const App = () => {
return <Camera color="red" size={48} />;
};
export default App;
属性
¥Props
name | type | default |
---|---|---|
size | number | 24 |
color | string | currentColor |
strokeWidth | number | 2 |
absoluteStrokeWidth | 布尔值 | false |
应用属性
¥Applying props
要自定义图标的外观,你可以将自定义属性作为 props 直接传递给组件。该组件接受所有 SVG 属性作为属性,从而允许灵活地设置 SVG 元素的样式。
¥To customize the appearance of an icon, you can pass custom properties as props directly to the component. The component accepts all SVG attributes as props, which allows flexible styling of the SVG elements.
// Usage
const App = () => {
return <Camera fill="red" />;
};
使用 Lucide Lab 或自定义图标
¥With Lucide lab or custom icons
Lucide Lab 是一个图标集合,不属于 Lucide 主库。
¥Lucide lab is a collection of icons that are not part of the Lucide main library.
它们可以通过 Icon
组件使用。所有与常规 Lucide 图标类似的属性都可以通过传递来调整图标外观。
¥They can be used by using the Icon
component. All props like regular lucide icons can be passed to adjust the icon appearance.
使用 Icon
组件
¥Using the Icon
component
这将根据传递的 iconNode 创建一个图标,并渲染一个 Lucide 图标组件。
¥This creates a single icon based on the iconNode passed and renders a Lucide icon component.
import { Icon } from 'lucide-react-native';
import { coconut } from '@lucide/lab';
const App = () => (
<Icon iconNode={coconut} />
);
一个通用图标组件
¥One generic icon component
可以创建一个通用的图标组件来加载图标,但不建议这样做。
¥It is possible to create one generic icon component to load icons, but it is not recommended.
警告
以下示例导入了所有 ES 模块,因此使用时请谨慎。导入所有图标将显著增加应用的构建大小,从而对其性能产生负面影响。在使用 Webpack
、Rollup
或 Vite
等打包器时,这一点尤为重要。
¥The example below imports all ES Modules, so exercise caution when using it. Importing all icons will significantly increase the build size of the application, negatively affecting its performance. This is especially important to keep in mind when using bundlers like Webpack
, Rollup
, or Vite
.
图标组件示例
¥Icon Component Example
import { icons } from 'lucide-react-native';
const Icon = ({ name, color, size }) => {
const LucideIcon = icons[name];
return <LucideIcon color={color} size={size} />;
};
export default Icon;
使用图标组件
¥Using the Icon Component
import Icon from './Icon';
const App = () => {
return <Icon name="house" />;
};
export default App;