Quellcode durchsuchen

Update 'App.js'

Updated App.js
mortimel.ojeda vor 2 Jahren
Ursprung
Commit
344a5ee338
1 geänderte Dateien mit 64 neuen und 36 gelöschten Zeilen
  1. 64
    36
      App.js

+ 64
- 36
App.js Datei anzeigen

@@ -1,44 +1,72 @@
1
-import { StatusBar } from 'expo-status-bar';
2
-import React from 'react';
3
-import { StyleSheet, Text, View } from 'react-native';
4
-
5
-
6
-export default function App() {
7
-  return (
8
-    <View style={styles.container}>
9
-      <Text>"Hello"</Text>
10
-      <StatusBar style="auto" />
11
-    </View>
12
-  );
1
+import React, { Component } from 'react';
2
+import firebase from 'firebase'
3
+import { NavigationContainer } from '@react-navigation/native';
4
+import { createStackNavigator } from '@react-navigation/stack';
5
+
6
+import RegisterScreen from './screens/RegisterScreen';
7
+import LoginScreen from './screens/LoginScreen';
8
+import { firebaseConfig } from './config/firebaseConfig';
9
+import { Text, View } from 'react-native';
10
+import { styles } from './config/styles';
11
+
12
+if (firebase.apps.length === 0) {
13
+  firebase.initializeApp(firebaseConfig)
13 14
 }
14 15
 
16
+const Stack = createStackNavigator();
15 17
 
16
-// Import the functions you need from the SDKs you need
17
-// import { initializeApp } from "firebase/app";
18
-// TODO: Add SDKs for Firebase products that you want to use
19
-// https://firebase.google.com/docs/web/setup#available-libraries
18
+export default class App extends Component {
19
+  constructor(props){
20
+    super(props);
21
+    this.state = {
22
+      loaded: false,
23
+    }
24
+  }
25
+  
26
+  componentDidMount(){
27
+    firebase.auth().onAuthStateChanged((user) => {
28
+      if (!user){
29
+        this.setState({
30
+          loggedIn: false,
31
+          loaded: true,
32
+        })
33
+      }
34
+      else{
35
+        this.setState({
36
+          loggedIn: true,
37
+          loaded: true,
38
+        })
39
+      }
40
+    })
41
+  }
20 42
 
21
-import firebase from "firebase";
43
+  render() {
22 44
 
23
-// Your web app's Firebase configuration
24
-const firebaseConfig = {
25
-  apiKey: "AIzaSyDW-ABAQ3r_WR7C7WC_3VprL77NcAoitJI",
26
-  authDomain: "freehand-d8ecd.firebaseapp.com",
27
-  projectId: "freehand-d8ecd",
28
-  storageBucket: "freehand-d8ecd.appspot.com",
29
-  messagingSenderId: "48371388186",
30
-  appId: "1:48371388186:web:9a5a4bf1218e17ac6326a3"
31
-};
45
+    const { loggedIn, loaded } = this.state
32 46
 
33
-// Initialize Firebase
34
-const app = firebase.initializeApp(firebaseConfig);
47
+    if(!loaded){
48
+      return(
49
+        <View style={styles.regcontainer}>
50
+          <Text>Hopper</Text>
51
+        </View>
52
+      );
53
+    }
35 54
 
55
+    if(!loggedIn){
56
+      return (
57
+        <NavigationContainer>
58
+          <Stack.Navigator>
59
+            <Stack.Screen name={" "} options={{headerShown: false}} component={LoginScreen}/>
60
+            <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
61
+          </Stack.Navigator>
62
+        </NavigationContainer>
63
+      );
64
+    }
36 65
 
37
-const styles = StyleSheet.create({
38
-  container: {
39
-    flex: 1,
40
-    backgroundColor: '#fff',
41
-    alignItems: 'center',
42
-    justifyContent: 'center',
43
-  },
44
-});
66
+    return(
67
+      <View style={styles.regcontainer}>
68
+        <Text>Cheese</Text>
69
+      </View>
70
+    );
71
+  }
72
+}