[英]how to add @expo/vector-icons in react native app?
i am using @expo/vector-icons here is my package.json file我正在使用 @expo/vector-icons 这是我的 package.json 文件
"dependencies": {
"@expo/vector-icons": "^4.1.1",
"color": "^1.0.3",
"expo": "^30.0.1",
"moment": "^2.22.2",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-
30.0.0.tar.gz",
"react-native-extended-stylesheet": "^0.4.0" },
when i import @expo/vector-icon library in my component当我在组件中导入 @expo/vector-icon 库时
import { Ionicons } from '@expo/vector-icons';
In your dependencies (package.json) remove @expo/vector-icons. 在您的依赖项(package.json)中,删除@ expo / vector-icons。 They are included in the expo package and different versions of expo and expo/vector-icons can cause errors like this one. 它们包含在expo程序包中,expo和expo / vector-icons的不同版本可能会导致此类错误。
From the official docs : 从官方文档 :
This library is installed by default on the template project that get through expo init -- it is part of the expo package. 该库默认安装在通过expo init获得的模板项目上-它是expo软件包的一部分。 It includes popular icon sets and you can browse all of the icons using the @expo/vector-icons directory. 它包括流行的图标集,您可以使用@ expo / vector-icons目录浏览所有图标。
Delete your node module folder and run expo init. 删除您的节点模块文件夹,然后运行expo init。 And run the project 并运行项目
The library comes by default so you don't need to install @expo/vector-icons. 该库是默认提供的,因此您不需要安装@ expo / vector-icons。
You can just do this for example: 您可以例如这样做:
import { Ionicons } from '@expo/vector-icons';
and then you can use it like: 然后您可以像这样使用它:
<Ionicons name="ios-pizza" color="red" size={200} />
FYI, this directory is helpful in finding different icons https://expo.github.io/vector-icons/ 仅供参考,此目录有助于查找不同的图标https://expo.github.io/vector-icons/
Have you noticed that I want to use create-react-native-app
instead of expo init
and later on use expo icons你有没有注意到我想使用create-react-native-app
而不是expo init
并且稍后使用 expo 图标
npm i -g create-react-native-app
create-react-native-app my-project
cd my-project
npm start
go to 'https://icons.expo.fyi/' choose whatever you want, first import via copy,then use it.转到“https://icons.expo.fyi/”选择您想要的任何内容,首先通过复制导入,然后使用它。 look example看例子
import React from 'react' import { Entypo } from '@expo/vector-icons'; import {View} from 'react-native'; export const Example=()=>{ return( <View> <Entypo style={styles.editDown} name="plus" size={24} color="black" /> </View> ) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.