react-native-vector-icons,TabBarItem元素类型无效

时间:2017-05-17 02:49:51

标签: react-native expo

我想更改TabBarIOS的图标并编写以下代码,但是元素类型的错误无效。

import React from 'react';
import { View, TabBarIOS } from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
import CommunicationTab from './components/communication_tab';
import WhereaboutsTab from './components/whereabouts_tab';

export default class App extends React.Component {

  constructor() {
    super();
    this.state = {
      selectedTab: 'WhereaboutsTab',
    };
  }

  render() {
    return (
      <TabBarIOS selectedTab={this.state.selectedTab}>
        <Icon.TabBarItem
          title="whereabouts"
          iconName='ios-home-outline'
          selectedIconName='ios-home'
          selected={this.state.selectedTab === 'WhereaboutsTab'}
          onPress={() => {
            this.setState({
              selectedTab: 'WhereaboutsTab'
            });
          }}
        >
          <WhereaboutsTab />
        </Icon.TabBarItem>
        <Icon.TabBarItem
          title="communication"
          iconName='ios-settings-outline'
          selectedIconName='ios-settings'
          selected={this.state.selectedTab === 'CommunicationTab'}
          onPress={() => {
            this.setState({
              selectedTab: 'CommunicationTab'
            });
          }}
        >
          <CommunicationTab />
        </Icon.TabBarItem>
      </TabBarIOS>
    );
  }
}

enter image description here

使用以下代码时,没有任何问题。

<Icon name="ios-home" />

这是我在create-react-native-app中制作的一个expo项目,这是否相关?

的package.json

"dependencies": {
    "expo": "^16.0.0",
    "moment": "^2.18.1",
    "react": "16.0.0-alpha.6",
    "react-native": "^0.43.4",
    "react-native-action-button": "^2.6.9",
    "react-native-md-textinput": "^2.0.4",
    "react-native-modal-datetime-picker": "^4.6.0",
    "react-native-swipeout": "^2.1.1",
    "react-native-vector-icons": "^4.1.1"
}

1 个答案:

答案 0 :(得分:0)

我认为你有错字。

请尝试将Icon.TabBarItem替换为Icon.TabBarItemIOS