-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
118 lines (110 loc) · 3.55 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React, { useState, useEffect, useMemo } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import createAnAccount from './screens/CreateAnAccount';
import CreateBusinessAccount from './screens/CreateBusinessAccount';
import CreatePersonalAccount from './screens/CreatePersonalAccount';
import SignIn from './screens/SignIn';
import { createDrawerNavigator } from '@react-navigation/drawer';
import Splash from './screens/Splash';
import { AuthContext } from './context';
import TabsStackScreen from './stacks/tabsStack';
import ProfileStackScreen from './stacks/profileStack';
import CreateBusinessAccount2 from './screens/CreateBusinesPage2';
const AuthStack = createNativeStackNavigator();
const Drawer = createDrawerNavigator();
export default function App() {
const [isLoading, setIsLoading] = useState(true);
const [userToken, setUserToken] = useState(false);
console.log(userToken, '<<< state set');
const authContext = useMemo(() => {
return {
userToken: userToken,
signIn: (username, password) => {
setUserToken('hello');
setIsLoading(false);
},
signUp: () => {
setIsLoading(false);
setUserToken('abc');
},
signOut: () => {
setIsLoading(false);
setUserToken(null);
}
};
}, []);
useEffect(() => {
setTimeout(() => {
setIsLoading(false);
}, 1000);
});
if (isLoading) return <Splash />;
return (
<AuthContext.Provider value={authContext}>
<NavigationContainer>
{userToken ? (
<Drawer.Navigator
screenOptions={{
drawerPosition: 'right',
headerShown: false,
drawerType: 'front',
initialState: { userToken }
}}
>
<Drawer.Screen
name="DrawHome"
component={TabsStackScreen}
options={{ title: 'Home' }}
/>
<Drawer.Screen
name="DrawProfile"
component={ProfileStackScreen}
options={{ title: 'Profile' }}
/>
</Drawer.Navigator>
) : (
<AuthStack.Navigator>
<AuthStack.Screen
name="signIn"
component={SignIn}
options={{ title: 'Sign In', headerTitleAlign: 'center' }}
/>
<AuthStack.Screen
name="signUp"
component={createAnAccount}
options={{
title: 'Create An Account',
headerTitleAlign: 'center'
}}
/>
<AuthStack.Screen
name="CreateBusinessAccount"
component={CreateBusinessAccount}
options={{
title: 'Create A Business Account',
headerTitleAlign: 'center'
}}
/>
<AuthStack.Screen
name="CreateBusinessAccount2"
component={CreateBusinessAccount2}
options={{
title: 'Create A Business Account 2nd page',
headerTitleAlign: 'center'
}}
/>
<AuthStack.Screen
name="CreatePersonalAccount"
component={CreatePersonalAccount}
options={{
title: 'Create A Personal Account',
headerTitleAlign: 'center'
}}
/>
</AuthStack.Navigator>
)}
</NavigationContainer>
</AuthContext.Provider>
);
}