-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathApp.tsx
55 lines (47 loc) · 1.78 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
import React, { useState } from 'react';
import { StyleSheet, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import AppLoading from 'expo-app-loading';
import AppNavigator from './app/navigation/AppNavigator';
import { AuthContext } from './app/auth/context';
import AuthNavigator from './app/navigation/AuthNavigator';
import OfflineNotice from './app/components/OfflineNotice';
import authStorage from './app/auth/storage';
import { navigationRef } from './app/navigation/routeNavigation';
import navigationTheme from './app/navigation/navigationTheme';
import colors from './app/config/colors';
export default function App() {
const [user, setUser] = useState(null);
const [isReady, setIsReady] = useState(false);
const restoreUser = async () => {
const currentUser = await authStorage.getUser();
if (currentUser) setUser(currentUser);
};
const handleLoadingError = () => {
throw new Error('App loading error');
};
const handleLoadingFinish = () => setIsReady(true);
if (!isReady)
return (
<AppLoading
startAsync={restoreUser}
onError={handleLoadingError}
onFinish={handleLoadingFinish}
/>
);
return (
<View style={styles.container}>
<AuthContext.Provider value={{ user, setUser }}>
<OfflineNotice />
<NavigationContainer
theme={navigationTheme}
ref={navigationRef}>
{user ? <AppNavigator /> : <AuthNavigator />}
</NavigationContainer>
</AuthContext.Provider>
</View>
);
}
const styles = StyleSheet.create({
container: { backgroundColor: colors.white, flex: 1 }
});