在标签栏中显示组件react-native-router-flux

时间:2018-06-22 09:32:59

标签: react-native svg react-native-router-flux

我正在使用react-native-router-flux在我的应用中进行导航。我有一个标签导航,我想在其中添加一些svg作为标签图标。我使用react-native-svg处理svg文件。

这是我的标签页的路由器代码:

import Chrono from './components/assets/Chrono'
const ChronoIcon = () => {
  return (
    <Chrono style={{width:10, height: 10}} fill="#8CCDF8"/>
  );
};
    <Scene key='root' tabs={true} tabBarPosition='top'>
                   <Scene key='chrono' hideNavBar tabBarLabel={'Something'} component={Starter} icon={ChronoIcon}/>
                   <Scene key='time' hideNavBar title='TIME' component={TimeCardList} icon={TabIcon}/>
                   <Scene key='client' hideNavBar title='CLIENT' component={ClientList} icon={TabIcon}/>
                   <Scene key='project' hideNavBar title='PROJECT' component={ProjectList} icon={TabIcon}/>
                   <Scene key='info' hideNavBar title='INFO' component={Info} icon={TabIcon}/>
                </Scene>

如您所见,我希望我的第一个场景是通过ChronoIcon函数显示我的Chrono的选项卡。这是Chrono组件的代码:

import React, { Component } from 'react';
import Svg,{
    Circle,
    Ellipse,
    G,
    LinearGradient,
    RadialGradient,
    Line,
    Path,
    Polygon,
    Polyline,
    Rect,
    Symbol,
    Text,
    Use,
    Defs,
    Stop
} from 'react-native-svg';


class Chrono extends Component {
    render() {
        return (
          <Svg
              style={this.props.style}
              viewBox="0 0 75 87.5"
          >
            <Path
              fill={this.props.fill}
              d="M66.8,26.76A37.41,37.41,0,1,1,37.5,12.5a38.13,38.13,0,0,1,23.44,8.4l5.86-6.06a41.61,41.61,0,0,1,5.86,5.86ZM37.5,79.3A29.2,29.2,0,1,0,8.4,50,29.09,29.09,0,0,0,37.5,79.3ZM50,0V8.4H25V0Z"/>
            <Polyline
              fill={this.props.fill}
              points="31.9 63.35 31.9 37.35 50.1 50.35"/>
        </Svg>
        );
    }
}

export default Chrono;

但是似乎没有任何效果,唯一显示的是tabBarLabel:

enter image description here

如何从react-native-router-flux在标签栏中显示我的svg组件?

1 个答案:

答案 0 :(得分:1)

我找到了答案。

使用这样的renderTitle,并且可以在其中放入任何类型的svg。

<Scene
   key="emaillogin"
   component={LoginEmail}
   renderTitle={() => (
       <View style={styles.headerLogoView}>
          <Logo />
       </View>
   )}
/>

const styles = {
    headerLogoView: {
    flexDirection: 'row',
    paddingLeft: 5,
    paddingTop: 5,
    width: '100%', 
    height: '100%', 
},

};

使用svg创建文件