-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
70 lines (62 loc) · 2.08 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
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { PortalProvider } from '@gorhom/portal';
import * as Notifications from 'expo-notifications';
/** Routes */
import Home from './pages/Home';
import Login from './pages/Login';
import Register from './pages/Register';
import { useEffect, useState } from 'react';
import { ActivityIndicator, View } from 'react-native';
import { colors } from './config/styles';
import { theme } from './config';
import { isLoggedStorage } from './services/AsyncStorage';
const Stack = createStackNavigator();
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
const App = () => {
const [isLoading, setIsLoading] = useState(true);
const [defaultScreen, setDefaultScreen] = useState('Login');
useEffect(() => {
const fetchIsLogged = async () => {
const isLogged = (await isLoggedStorage.getValues()).length > 0;
if (isLogged) {
setDefaultScreen('Home');
}
setIsLoading(false);
}
fetchIsLogged();
}, []);
return (isLoading ? <Loading /> : (
<GestureHandlerRootView style={{ flex: 1 }}>
<PortalProvider>
<NavigationContainer>
<Stack.Navigator
initialRouteName={defaultScreen}
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Register" component={Register} />
</Stack.Navigator>
</NavigationContainer>
</PortalProvider>
</GestureHandlerRootView>
));
}
const Loading = () => {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: colors(theme).bg[1] }}>
<ActivityIndicator size="large" color={colors(theme).white} />
</View>
);
}
export default App;