-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAppLoadingContainer.tsx
63 lines (54 loc) · 1.74 KB
/
AppLoadingContainer.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
import 'react-native-reanimated';
import 'react-native-gesture-handler';
import React, { useEffect } from 'react';
import { ActivityIndicator, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import AuthNavigator from './src/modules/navigation/AuthNavigator';
import MainStackNavigator from './src/modules/navigation/MainStackNavigator';
import RouteNames from './src/modules/navigation/route_names/app';
import ParamList from './src/modules/navigation/param_list/app';
import { useFonts } from './src/hooks/useFonts';
import useStore from './src/store';
const Stack = createStackNavigator<ParamList>();
const AppLoadingContainer = () => {
const token = useStore((s) => s.token);
const initUser = useStore((s) => s.initUser);
const isLoading = useStore((s) => s.isLoading);
const fontsLoaded = useFonts();
useEffect(() => {
const init = async () => {
await initUser();
};
init();
}, []);
if (!fontsLoaded || isLoading) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ActivityIndicator />
</View>
);
}
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={() => ({
headerShown: false,
})}
>
{token ? (
<Stack.Screen name={RouteNames.home} component={MainStackNavigator} />
) : (
<Stack.Screen
name={RouteNames.authNav}
component={AuthNavigator}
options={{
animationTypeForReplace: 'push',
}}
/>
)}
</Stack.Navigator>
</NavigationContainer>
);
};
export default AppLoadingContainer;