3

我对 react-navigation 选项卡导航器有疑问。屏幕内容未显示/屏幕为空白。有任何想法吗 ?这是我的导航器结构:

import { StackNavigator, TabNavigator } from 'react-navigation';
import PeopleList from './PeopleList';
import CompanyList from './CompanyList';
import AddPerson from './AddPerson';
const Navigation = TabNavigator({
  People: { screen: PeopleList },
  Person: { screen: AddPerson },
  Company: { screen: CompanyList },
 }, {
 tabBarOptions: {
  activeTintColor: 'white',
  inactiveTintColor: '#80cbc4',
  swipeEnabled: true,
  showLabel: false,
  style: {
    backgroundColor: '#26a69a',
  },
 },
});
export default Navigation;

更新:

这是包含渲染方法的 App.js 文件:

    import React, {Component} from 'react';
    import {StyleSheet, Text, View} from 'react-native';
    import firebase from 'firebase';
    import {Provider} from 'react-redux';
    import {createStore} from 'redux'
    import Login from './Login';
    import Loader from './Loader';
    import Navigation from './Navigation';
    import reducers from '../reducers/PeopleReducer';

    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF'
      }
    });

    const store = createStore(reducers);

    export default class App extends Component {
      state = {
        loggedIn: null
      };

      componentWillMount() {
        firebase.initializeApp({
          apiKey: "xxxxxxxxxxxxxxxxxxx",
          authDomain: "xxxxxxxxxxxxxxxxxxx",
          databaseURL: "xxxxxxxxxxxxxxxxxxx",
          projectId: "xxxxxxxxxxxxxxxxxxx",
          storageBucket: "xxxxxxxxxxxxxxxxxxx",
          messagingSenderId: "xxxxxxxxxxxxxxxxxxx"
        });

        firebase
          .auth()
          .onAuthStateChanged((user) => {
            if (user) {
              this.setState({loggedIn: true});
            } else {
              this.setState({loggedIn: false});
            }
          });
      }

      renderInitialView() {
        switch (this.state.loggedIn) {
          case true:
            return <Navigation/> /*exists above*/
          case false:
            return <Login/>;
          default:
            return <Loader size="large"/>;
        }
      }
      render() {
        return (
          <Provider store={store}>
            <View style={styles.container}>
              {this.renderInitialView()}
            </View>
          </Provider>
        );
      }
    }

我确定它适用于第一个 switch 案例,但是出现了一个空白屏幕,我不知道原因。

4

1 回答 1

5
render() {
    return (
      <Provider store={store}>
        <View style={styles.container}>
          {this.renderInitialView()}
        </View>
      </Provider>
    );
  }
}

移除标签导航不能被包裹在标签中,像这样。

render() {
    return (
      <Provider store={store}>

          {this.renderInitialView()}

      </Provider>
    );
  }
}

这将起作用。

于 2017-08-03T12:23:48.583 回答