安装
参考Ionicons
npm install react-native-vector-icons --save
这时候可能会报错:npm WARN deprcated lodash@4.2.0:This package is deprecated. Use Object.assign.
运行命令行
npm i --save lodash.assign
In Node.js:
var assign = require('lodash.assign');
npm install rnpm -g
rnpm link
使用
引入vector-icons:
var Icon = require('react-native-vector-icons/Ionicons');
修改组件值:eg.
Button -> Icon.Button
TabBarIOS.Item -> Icon.TabBarItem
修改属性值:eg.
icon -> iconName
selectedIcon -> selectedIconName
坑
碰到过Ionians导入不成功,错误提示信息为:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
于是我将 var Icon = require('react-native-vector-icons/Ionicons');
改为
import Icon from 'react-native-vector-icons/Ionicons';
导入成功