如何将tabBarComponent用于TabNavigator?标签栏未显示

问题描述 投票:3回答:2

我正在尝试创建自己的自定义标签栏,似乎tabBarComponent是通过设置为我自己的组件来实现的。使用以下代码,我的标签栏不会显示。

const TabNav = TabNavigator({
  LaunchScreen: {
      screen: PrimaryNav,
      navigationOptions: {
        tabBarLabel:'Find',
        tabBarIcon: ({ tintColor }) => (
          <Icon name='search' size={20} color='white' />
        ),
      },
   },
}, {
  navigationOptions: {
    headerTintColor: 'grey'
  },
  tabBarComponent: FooterTabs,
  tabBarPosition: 'bottom',
  swipeEnabled:false,
  animationEnabled:false,
  lazy:true,
  tabBarOptions: {
      showIcon:true,
      showLabel:false,
      style: {
          backgroundColor: 'black'
      }
  }
});

在FooterTabs.js中:

export default class FooterTabs extends Component {
  render () {
    return (
      <View style={styles.container}>
        <Text>FooterTabs Component</Text>
      </View>
    )
  }
}

我错过了什么?

javascript react-native react-navigation tabnavigator
2个回答
3
投票
    const TabNav = TabNavigator({
      ......,
     tabBarComponent: props => (
     <FooterTabs{...props} />
     ),
     tabBarPosition: 'bottom',
     ........

    });

试试吧。封装你的FooterTabs,即<FooterTabs />而不是FooterTabs


1
投票

经过一些试验和错误,我的问题的解决方案是将我的页脚内容包装在ScrollView中,然后选项卡按预期显示,但我不确定为什么需要它。

我还实现了Caleb的建议(谢谢!)使用tabBarComponent: props => <FooterTabs{...props} />以传递我需要的道具虽然不是问题的原因。

© www.soinside.com 2019 - 2024. All rights reserved.