TabNavigator的headerLeft问题

时间:2019-01-28 11:58:53

标签: react-native

为什么导航中不显示我放在标题左参数上的图标?在我看来,每件事都是正确的,Icon已导入。您能帮忙找到问题吗,这是我的代码:

const TabBarNavig = TabNavigator({
  Places  : {
    screen :AddPlaces,
    navigationOptions: ({ navigation }) => ({
      title: 'Placements'
    })
  },
  GetPlaces : GetPlaces,
  New : New
});

TabBarNavig.navigationOptions = ({ navigation }) => {
  const { state: { routes, index } } = navigation; 
  const navigationOptions = {};
  navigationOptions.headerLeft = () => {
    return (
      <Icon 
        name = 'menu'
        size = { 20}
        color = 'white'
        style={{paddingTop:20}}
      /> 
    );
  }
};

3 个答案:

答案 0 :(得分:0)

如果使用反应导航版本3,则必须使用defaultNavigationOptions代替navigationOptions

答案 1 :(得分:0)

如果您尝试将图标放在选项卡本身的顶部,则必须使用StackNavigator

const TabBarNavig = TabNavigator({
  //your component here
})

const YNavigator = StackNavigator ({
  Home:{screen: TabBarNavig,
    navigationOptions: ({navigation}) => ({
      headerLeft: <Icon name="menu" size={20} color="white" />,
    })
  },
})

答案 2 :(得分:0)

const TabBarNavig = TabNavigator({
  Places  : {
    screen :AddPlaces,
    navigationOptions: ({ navigation }) => ({
      title: 'Placements'
    })
  },
  GetPlaces : GetPlaces,
  New : New
});

createBottomTabNavigator

替换 TabNavigator
const TabBarNavig = createBottomTabNavigator({
  Places  : {
    screen :AddPlaces,
    navigationOptions: ({ navigation }) => ({
      title: 'Placements'
    })
  },
  GetPlaces : GetPlaces,
  New : New
});

我认为这可以解决您的问题