-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainNavigation.js
More file actions
88 lines (83 loc) · 2.57 KB
/
MainNavigation.js
File metadata and controls
88 lines (83 loc) · 2.57 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
import AsyncStorage from '@react-native-async-storage/async-storage';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import React, {useEffect, useState} from 'react';
import {StyleSheet, View} from 'react-native';
import {ActivityIndicator} from 'react-native-paper';
import {useLoggedIn} from './hooks/useLoggedIn';
import AdminLogin from './screen/authentication/AdminLogin';
import Home from './screen/HomeNavigation';
import Login from './screen/authentication/Login';
import ProgramDetails from './screen/programs/ProgramDetails';
import Programs from './screen/programs/ProgramNavigation';
import Register from './screen/authentication/Register';
const MainNavigation = () => {
const {isLoggedIn, data, pending} = useLoggedIn();
const [loading, setLoading] = useState(true);
const Stack = createNativeStackNavigator();
useEffect(() => {
const check = async () => {
if (!pending) {
setLoading(false);
if (data) {
await AsyncStorage.setItem('userId', data.id);
}
}
};
check()
}, [pending]);
return (
<>
{loading ? (
<View style={styles.wrapper}>
<ActivityIndicator size="large" />
</View>
) : (
<NavigationContainer>
<Stack.Navigator initialRouteName={isLoggedIn ? 'home' : 'login'}>
<Stack.Screen
name="home"
component={Home}
options={{header: () => null}}
/>
<Stack.Screen name="programs" component={Programs} />
<Stack.Screen
name="programDetails"
component={ProgramDetails}
options={({route}) => ({
title: route.params.title,
})}
/>
<Stack.Screen
name="login"
component={Login}
options={{header: () => null}}
/>
<Stack.Screen
name="register"
component={Register}
options={{header: () => null}}
/>
<Stack.Screen
name="adminLogin"
component={AdminLogin}
options={{header: () => null}}
/>
</Stack.Navigator>
</NavigationContainer>
)}
</>
);
};
const styles = StyleSheet.create({
wrapper: {
position: 'absolute',
width: '100%',
height: '100%',
backgroundColor: 'white',
justifyContent: 'center',
alignItems: 'center',
zIndex: 1,
},
});
export default MainNavigation;