Ionicons的使用

安装

参考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';导入成功

posted @ 2016-10-24 22:05  早上好王木木  阅读(5101)  评论(1编辑  收藏  举报