-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
51 lines (42 loc) · 1.43 KB
/
App.js
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
import React,{ useState, useEffect } from 'react';
import { View, Text, Button, ActivityIndicator } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import auth from '@react-native-firebase/auth';
import LoginScreen from './src/auth/Login'
import RegisterScreen from './src/auth/Register';
import MainApp from './src/MainApp';
const Stack = createNativeStackNavigator();
const App = () => {
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
function onAuthStateChanged(user) {
setUser(user);
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber;// unsubscribe on unmount
}, []);
if(initializing){
return(
<View style={{flex:1, backgroundColor:'#1d242f', justifyContent:'center', alignItems:'center'}}>
<ActivityIndicator size="large" color="#009394"/>
</View>
)
}
if(user){
return(
<MainApp />
)
}
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Login" component={LoginScreen} options={{ headerShown:false}} />
<Stack.Screen name="Register" component={RegisterScreen} options={{ headerShown:false }} />
</Stack.Navigator>
</NavigationContainer>
)
}
export default App;