-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
95 lines (93 loc) · 2.85 KB
/
App.js
File metadata and controls
95 lines (93 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React, { Component } from "react";
import "react-native-gesture-handler";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { View, Text, ActivityIndicator } from "react-native";
import * as firebase from "firebase";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import rootReducer from "./Redux/reducers";
import thunk from "redux-thunk";
// ************************ Components ***********************//
import WelcomeScreen from "./App/views/WelcomeScreen";
import Main from "./App/views/Main";
import Login from "./App/views/Components/Authentication/Login";
import Register from "./App/views/Components/Authentication/Register";
const store = createStore(rootReducer, applyMiddleware(thunk));
const Stack = createStackNavigator();
const firebaseConfig = {
apiKey: "AIzaSyDwMnPFWAqwD2fvqtS--0Zqf-nvet1jrNQ",
authDomain: "simsub-1.firebaseapp.com",
projectId: "simsub-1",
storageBucket: "simsub-1.appspot.com",
messagingSenderId: "65161035779",
appId: "1:65161035779:web:9eff179fbaea84da08ce36",
measurementId: "G-3HMN5XL9DG",
};
if (firebase.apps.length === 0) {
firebase.initializeApp(firebaseConfig);
}
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
loaded: false,
guest: false,
};
}
componentDidMount() {
firebase.auth().onAuthStateChanged((user) => {
if (!user) {
this.setState({ loggedIn: false, loaded: true });
} else {
this.setState({ loggedIn: true, loaded: true });
}
});
}
render() {
const { loggedIn, loaded } = this.state;
const { guest } = this.state;
if (!loaded) {
return (
<View style={{ flex: 1, justifyContent: "center" }}>
<ActivityIndicator size="large" />
</View>
);
}
if (!loggedIn && !guest) {
return (
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Welcome"
component={WelcomeScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Login"
component={Login}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Register"
component={Register}
options={{ headerBackTitleVisible: false }}
/>
<Stack.Screen
name="Main"
component={Main}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
);
}
return (
<Provider store={store}>
<Main />
</Provider>
);
}
}