简体   繁体   English

如何在本机应用程序中添加@expo/vector-icons?

[英]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';

it gives error它给出了错误在此处输入图片说明

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.

相关问题 BottomNavigation在React Native中不显示@ expo / vector-icons - BottomNavigation does not show @expo/vector-icons in React Native 反应本机! @expo/vector-icons/Fontisno 的问题 - React-native! Problem with @expo/vector-icons/Fontisno react-native-vector-icons 或 @expo/vector-icons 未在 Android 设备上呈现 - react-native-vector-icons or @expo/vector-icons not rendering on android device 导入&#39;react-native-vector-icon&#39; 结果&#39;无法解析模块&#39;@expo/vector-icons&#39; 错误 - Importing 'react-native-vector-icon' results 'Unable to resolve module '@expo/vector-icons' error 尝试在 vanilla React Native 项目中解决 @expo/vector-icons/FontAwesome 时出错 - Error trying to resolve @expo/vector-icons/FontAwesome in a vanilla React Native project React Native - 图标名称的 expo/vector-icons typescript 类型定义 - React Native - expo/vector-icons typescript type definition for icon name Native-React + Expo:无法从“src/boot/setup.js”解析“@expo/vector-icons/fonts/Ionicons.ttf” - Native-React + Expo: Unable to resolve "@expo/vector-icons/fonts/Ionicons.ttf" from "src/boot/setup.js" @ expo / vector-icons,如何使用react-navigation加载字体 - @expo/vector-icons, how to load font using react-navigation react native-vector-icons:将名称更改为简单文本 - react native- vector-icons: change the name to simple text react-native 纸按钮矢量图标向右浮动 - react-native paper button vector-icons float right
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM