TabIcon没有反作用

时间:2018-04-14 05:19:52

标签: react-native react-router

我不明白为什么我的IconTab组件没有被使用。只显示文字。

我的包装:

  • " native-base":" ^ 2.4.1",
  • "反应":" 16.3.0-alpha.1"," react-native":
  • " https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz",
  • " react-native-router-flux":" ^ 4.0.0-beta.28",

我的代码:

class TabIcon extends React.Component {
  render() {
    const color = `#${Math.floor(Math.random()* 10)}${Math.floor(Math.random() * 10)}${Math.floor(Math.random() * 10)}`
    return (
      <View style={{backgroundColor: color, width: '100%', height: '100%', justifyContent: 'center'}}>
        <Text style={{color: this.props.selected ? 'pink' :'white', textAlign: 'center', fontSize :20}}>{this.props.title}</Text>
      </View>
    );
  }
}

export default class App extends React.Component {
  state = {
    isLoadingComplete: false,
  };

  render() {
    if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
      return (
        <AppLoading
          startAsync={this._loadResourcesAsync}
          onError={this._handleLoadingError}
          onFinish={this._handleFinishLoading}
        />
      );
    } else { 
      return (
      <Router hideNavBar={true}>
        <Scene key="root" hideNavBar={true}>

          {/* Tab Container */}
          <Scene key="tabbar" tabs={true} tabBarStyle={style.tabBarStyle} hideNavBar={true}>
              <Scene key="LiveTracker" component={LiveTracker} title="Live trackeur" hideNavBar={true} icon={TabIcon} initial={true}  />
              <Scene key="BillGenerator" component={BillGenerator} title="Factures" hideNavBar={true} icon={TabIcon}  />

          </Scene>
        </Scene>
      </Router>
      );
    }
  }

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您需要在Icon Name中提供Tab Scene才能显示图标

<强> App.js

import Icon from 'react-native-vector-icons/FontAwesome';

 <Scene key="LiveTracker" iconName="tags" component={LiveTracker} title="Live trackeur" hideNavBar={true} icon={TabIcon} initial={true}  />
 <Scene key="BillGenerator" iconName="newspaper-o" component={BillGenerator} title="Factures" hideNavBar={true} icon={TabIcon}  />

并将其传递给您的TabIcon component,如下所示

<强> TabIcon.js

<View style={{backgroundColor: color, width: '100%', height: '100%', justifyContent: 'center'}}>
        <Icon style={{color: color}} name={this.props.iconName || "circle"} size={18}/>
        <Text style={{color: this.props.selected ? 'pink' :'white', textAlign: 'center', fontSize :20}}>{this.props.title}</Text>
      </View>

检查展示位置react-native-vector-icons