-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
77 lines (67 loc) · 2.34 KB
/
App.tsx
File metadata and controls
77 lines (67 loc) · 2.34 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
import React, { useEffect, useState, FC, createContext } from "react";
import NavigationComponent from "./src/components/NavigationComponent";
import AsyncStorage from '@react-native-async-storage/async-storage';
import LoadingPage from "./src/page/LoadingPage";
import { check, PERMISSIONS, RESULTS, request } from 'react-native-permissions';
type UserDataType = {
userId: string;
familyId: string;
};
type UserContextType = {
userId: string | null,
familyId: string | null,
setUserData: (userId: string, familyId: string) => void,
};
export const UserContext = createContext<UserContextType>({
userId: null,
familyId: null,
setUserData: () => {},
});
const App: FC = () => {
const [isLoading, setIsLoading] = useState<boolean>(true);
const [userId, setUserId] = useState<string | null>('user4');
const [familyId, setFamilyId] = useState<string | null>('A1B5E6');
useEffect(() => {
const loadInitialData = async () => {
try {
// AsyncStorage에서 값을 불러오기
const fetchedUserId = await AsyncStorage.getItem('userId');
const fetchedFamilyId = await AsyncStorage.getItem('familyId');
if (!fetchedUserId || !fetchedFamilyId) {
// 로그인 페이지 실행
} else {
setUserId(fetchedUserId);
setFamilyId(fetchedFamilyId);
}
} catch (error) {
console.error('Error with AsyncStorage:', error);
}
// 앨범 접근 권한 및 카메라 사용 권한 요청
const permissions = [PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE, PERMISSIONS.ANDROID.CAMERA];
for (let permission of permissions) {
let result = await check(permission);
if (result !== RESULTS.GRANTED) {
result = await request(permission);
if (result !== RESULTS.GRANTED) {
console.log('Permission not granted: ', permission);
}
}
}
setIsLoading(false); // 로딩 완료
};
loadInitialData();
}, []);
const setUserData = ({ userId, familyId }: UserDataType) => {
setUserId(userId);
setFamilyId(familyId);
};
if (isLoading) {
return <LoadingPage />; // 로딩 중일 때는 로딩 페이지를 표시
}
return (
<UserContext.Provider value={{ userId, familyId, setUserData }}>
<NavigationComponent />
</UserContext.Provider>
);
}
export default App;