简体   繁体   English

机器人和ios的矢量图标

[英]Vector icons for android and ios

In https://www.npmjs.com/package/react-native-ionicons , we're given two ways to load icons for ios and android. https://www.npmjs.com/package/react-native-ionicons中 ,我们有两种方法来加载ios和android的图标。 I tried both approaches with v9.0.0 of @expo/vector-icons. 我用@ expo / vector-icons的v9.0.0尝试了这两种方法。

I import Ionicons with this statement: 我用这个声明导入Ionicons:

import { Ionicons } from '@expo/vector-icons';
  1. Remove ios/md from the name 从名称中删除ios / md
<Ionicons name="close-circle" size={25} style={{color: 'white'}} />

I get the below error which also happens for other icon names: 我得到以下错误,其他图标名称也会发生:

Warning: Failed prop type: Invalid prop name of value close-circle supplied to Icon, expected one of ... 警告:失败的道具类型:无效道具名称的值闭合圈提供给图标,预期的一个...

  1. If I pass ios/android properties instead, the icon just does not show up and I get no warning eg: 如果我传递ios / android属性,图标就不会显示,我没有得到警告,例如:
<Ionicons ios="ios-close-circle" android="md-close-circle" size={25} style={{color: 'white'}} />

My current fix is based on How can I create cross platform icon in react native? 我目前的修复是基于如何在本机中创建跨平台图标? . I use: 我用:

<Ionicons name={${Platform.OS === "ios" ? "ios" : "md"}-close-circle} size={25} style={{color: 'white'}} />

Is there a simpler way? 有更简单的方法吗?

Thank you! 谢谢!

Soo, the warning suggest the name you have supplied didn't match with the icons of Ionicons. 所以,警告提示你提供的名字与Ionicons的图标不符。 Two ways of solving it will be 解决它的两种方法是

  1. Passing correct name to the component. 将正确的名称传递给组件。 To find all the names visit here 要查找所有名称, 请访问此处
  2. import Ionicons from '@expo/vector-icons/Ionicons' . 从'@ expo / vector-icons / Ionicons'导入Ionicons。

Hope if helps you ! 希望能帮到你!

It appears that it was an oversight on my side. 看来这是对我的疏忽。 The README for @expo/vector-icons states: @ expo / vector-icons的README状态:

This library is a compatibility layer around @oblador/react-native-vector-icons to work with the Expo asset system. 该库是@ oblador / react-native-vector-icons周围的兼容层,可与Expo资产系统配合使用。

I don't know what got me to check the documentation for https://www.npmjs.com/package/react-native-ionicons but clearly the options that can be applied to it are not meant to work with @oblador/react-native-vector-icons and thus @expo/vector-icons... 我不知道是什么让我查看https://www.npmjs.com/package/react-native-ionicons的文档,但显然可以应用的选项并不适用于@ oblador / react -native-vector-icons和@ expo / vector-icons ...

For anyone interested in cross-platform icons with expo/vector-icons, you can refer to the question and solution provided from How can I create cross platform icon in react native? 对于任何对带有expo / vector-icons的跨平台图标感兴趣的人,您可以参考我如何在本机中创建跨平台图标提供的问题和解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM