我正在尝试使用本机导航,其中我为主页(有数据)创建两个不同的常量,为登录页面创建一个常量。我希望是否显示用户登录的主页,否则显示登录页面。
我正在尝试采用这种逻辑,但最终始终出现空白屏幕,而没有任何错误消息。
import React, { Component } from "react";
import { View } from "react-native";
import { createStackNavigator, createAppContainer } from "react-navigation";
import LoginScreen from "./components/Authentication/LoginScreen";
import HomeScreen from "./components/Home/HomeScreen";
import DataScreen from "./components/Data/DataScreen";
import SignUpScreen from "./components/Authentication/SignUpScreen";
import * as firebase from "firebase";
import Lava from "./components/Constants/Lava";
// Added pages in Stack Navigator
const MainAppStackNavigator = createStackNavigator({
Login: LoginScreen,
SignUp: SignUpScreen,
Home: HomeScreen
});
const RootAppStackNavigator = createStackNavigator({
Data: DataScreen
});
// Container where all pages saved for navigation
const MainAppContainer = createAppContainer(MainAppStackNavigator);
const RootAppContainer = createAppContainer(RootAppStackNavigator);
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
isUserAutheticated: false
};
// Firebase Constructor
if (!firebase.apps.length) {
firebase.initializeApp(Lava.fireBaseConfiguration);
}
firebase.auth().onAuthStateChanged(this.onAuthStateChanged);
}
onAuthStateChanged = user => {
this.setState({
isUserAutheticated: !!user
});
};
render() {
return (
<View>
{this.state.isUserAutheticated ? (
<MainAppContainer />
) : (
<RootAppContainer />
)}
</View>
);
}
}
请问我在哪里弄错了。