-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
63 lines (52 loc) · 1.54 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
52
53
54
55
56
57
58
59
60
61
62
63
import { StatusBar } from 'expo-status-bar';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import WelcomeScreen from './screens/WelcomeScreen';
import AuthScreen from './screens/AuthScreen';
import { useContext, useEffect, useState } from 'react';
import AuthContextProvider, { AuthContext } from './store/auth-context';
import IconButton from './components/IconButton';
const Stack = createNativeStackNavigator();
function AuthStack(){
return(
<Stack.Navigator>
<Stack.Screen name= "AuthScreen" component={AuthScreen} options={{
title: "Auth Screen"}}/>
</Stack.Navigator>
)
}
function AuthenticatedStack(){
const authCtx = useContext(AuthContext)
return(
<Stack.Navigator>
<Stack.Screen name="WelcomeScreen" component={WelcomeScreen} options={{
headerTitle: "Welcome Screen",
headerRight: ()=>(
<IconButton name='logout' size={30} color='darkblue' onPress={authCtx.logout}/>
)}}/>
</Stack.Navigator>
)
}
function Navigation(){
const authCtx = useContext(AuthContext)
return(
//conditional rendering
<NavigationContainer>
{!authCtx.isAuthenticated && <AuthStack/>}
{authCtx.isAuthenticated && <AuthenticatedStack/>}
</NavigationContainer>
)
}
function Root(){
return <Navigation/>
}
export default function App() {
return (
<>
<StatusBar style="auto" />
<AuthContextProvider>
<Root/>
</AuthContextProvider>
</>
);
}