-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
78 lines (68 loc) · 1.96 KB
/
App.tsx
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import AsyncStorage from '@react-native-async-storage/async-storage';
import {
NavigationContainer,
DefaultTheme,
DarkTheme,
} from '@react-navigation/native';
import React, {useEffect, useState, createContext} from 'react';
import {View, useColorScheme} from 'react-native';
import MainDrawerNavigator from './navigations/MainDrawerNavigator';
import MainStackNavigator from './navigations/MainStackNavigator';
import {getLoginStatus} from './services/productAPI';
import SplashScreen from 'react-native-splash-screen';
import {darkTheme, lightTheme} from './styles/theme';
export const ThemeContext = createContext({});
const ThemeProvider = ({children}: any) => {
const [theme, setTheme] = useState('light');
return (
<ThemeContext.Provider value={{theme, setTheme}}>
<NavigationContainer theme={theme == 'dark' ? darkTheme : lightTheme}>
{children}
</NavigationContainer>
</ThemeContext.Provider>
);
};
const App = () => {
const [loginStatus, setLoginStatus]: any = useState();
const getLogin = async () => {
let status = await AsyncStorage.getItem('loginStatus');
console.log('status', status);
if (status) {
setLoginStatus(JSON.parse(status));
} else {
setLoginStatus(false);
}
};
useEffect(() => {
getLogin();
}, []);
useEffect(() => {
console.log('loginStatus', loginStatus);
}, [loginStatus]);
if (loginStatus === true) {
SplashScreen.hide();
return (
<ThemeProvider>
<MainStackNavigator route={'Main'} />
</ThemeProvider>
);
} else if (loginStatus == false) {
return (
<ThemeProvider>
<MainStackNavigator route={'Login'} />
</ThemeProvider>
);
} else {
return <View></View>;
}
};
export default App;