react-navigation3选项卡容器问题

时间:2019-01-20 13:53:56

标签: react-native react-navigation

我在标签容器方面遇到了一些麻烦。尝试进行标签导航,但是我的空白页没有标签,也没有错误,我想我缺少了一些东西。

这是Root.js

import {createBottomTabNavigator, createAppContainer} from 'react-navigation';
// import {fire, auth, database } from './config/Config';
import FeedScreen from '../src/screens/FeedScreen';
import LearnScreen from '../src/screens/LearnScreen';
import PlayScreen from '../src/screens/PlayScreen';
import ProfileScreen from '../src/screens/ProfileScreen';


const tabContainer = createBottomTabNavigator({
  Feed: FeedScreen,
  Learn: LearnScreen,
  Play: PlayScreen,
  Profile: ProfileScreen
});

const RootContainer = createAppContainer(tabContainer);


export default class Root extends React.Component {

  render() {
    return (
      <View style={styles.container}>
        <RootContainer />

      </View>
    );
  }
}

我传递标签导航错误还是什么?为什么我有空白页。

1 个答案:

答案 0 :(得分:0)

您的代码中存在导出问题。正确的方法:

const tabContainer = createBottomTabNavigator({
  Feed: FeedScreen,
  Learn: LearnScreen,
  Play: PlayScreen,
  Profile: ProfileScreen
},{
  initialRouteName: 'Feed',
});


class Root extends React.Component {

  render() {
    return (
      <View style={styles.container}>
        <RootContainer />
      </View>
    );
  }
}

export default createAppContainer(tabContainer);

我还添加了initialRouteName: 'Feed',,您可以这样使用,首先要显示哪个页面。