-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoot.js
53 lines (44 loc) · 1.55 KB
/
Root.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
52
53
import 'react-native-gesture-handler';
import React, { useEffect, useState, useContext } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import UserContext from './src/Contexts/UserContext';
import { LoginScreen, HomeScreen, RegistrationScreen, NoteScreen } from './src/screens';
import { firebase } from './src/firebase/config';
import { decode, encode } from 'base-64';
if (!global.btoa) { global.btoa = encode; }
if (!global.atob) { global.atob = decode; }
const Stack = createStackNavigator();
export default function Root() {
const [loading, setLoading] = useState(true);
const userContext = useContext(UserContext);
// if (loading) return (<Text>loading</Text>)
useEffect(() => {
firebase.auth().onAuthStateChanged(user => {
if (user) {
userContext.setUid(user.uid)
userContext.setLoggedIn(true)
}
})
}, []);
return (
<NavigationContainer>
<Stack.Navigator>
{ userContext.loggedIn
? (
<>
<Stack.Screen name='Home' component={HomeScreen} />
<Stack.Screen name='Note' component={NoteScreen} />
</>
)
: (
<>
<Stack.Screen name='Login' component={LoginScreen} />
<Stack.Screen name='Registration' component={RegistrationScreen} />
</>
)
}
</Stack.Navigator>
</NavigationContainer>
)
}