App.js
2.89 KB
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
import React, {useState} from 'react';
import {StyleSheet, Text, View, Image, StatusBar, AsyncStorage} from 'react-native';
import {AppLoading} from "expo";
import {Asset} from 'expo-asset';
import {Provider} from 'react-redux';
import * as Font from 'expo-font'
import {Ionicons} from "@expo/vector-icons";
import {NavigationContainer} from "@react-navigation/native";
import store from './store';
import StackNavigation from "./navigations/StackNavigation";
import {AuthProvider} from "./AuthContext";
import {host} from './env';
import axios from "axios";
const cacheImages = (images) => {
return images.map((image) => {
if (typeof image === 'string') {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
})
};
const cacheFonts = (fonts) => {
return fonts.map((font) => {
return Font.loadAsync(font);
})
};
const App = () => {
const [isReady, setIsReady] = useState(false);
const [user, setUser] = useState('');
const loadAssets = async () => {
const images = cacheImages(
['https://images.unsplash.com/photo-1532278951723-545f655c97f9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60']
);
const fonts = cacheFonts([Ionicons.font]);
// await AsyncStorage.removeItem('cookie');
const cookie = await AsyncStorage.getItem('cookie');
console.log('cookie', cookie);
if (cookie) {
try {
axios.defaults.headers.Cookie = cookie;
console.log('user/loadMe 요청보냄', `http://${host}:4001/user/loadMe`);
const res = await axios.get(`http://${host}:4001/user/loadMe`);
const {user} = res.data;
console.log(user);
setUser(user);
} catch (e) {
console.error(e);
}
}
return Promise.all([images, fonts]);
};
const onFinish = () => {
setIsReady(true);
};
const onError = (err) => {
console.error(err)
};
return (
<>
{isReady
?
<Provider store={store}>
<AuthProvider user={user}>
<NavigationContainer>
<StatusBar barstyle={'light-content'}/>
<StackNavigation/>
</NavigationContainer>
</AuthProvider>
</Provider>
:
<AppLoading
startAsync={loadAssets}
onFinish={onFinish}
onError={onError}
/>
}
</>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});