-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
100 lines (86 loc) · 2.83 KB
/
Copy pathApp.tsx
File metadata and controls
100 lines (86 loc) · 2.83 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
100
import React, { useEffect, useCallback, useRef } from 'react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { NavigationContainer } from '@react-navigation/native';
import { FontLevelProvider } from './src/FontLevelProvider';
import { Platform, PermissionsAndroid } from 'react-native';
import Geolocation from 'react-native-geolocation-service';
import AppStack from './src/navigation/AppStack';
import AuthStack from './src/navigation/AuthStack';
import { navigationRef } from './src/navigation/NavigationRef';
import { useAuth, AuthProvider } from './src/AuthContext';
import AsyncStorage from '@react-native-async-storage/async-storage';
async function requestLocationPermission(): Promise<boolean> {
if (Platform.OS !== 'android') return true;
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: '위치 권한 필요',
message: '앱 이용을 위해 현재 위치가 필요합니다.',
buttonPositive: '허용',
buttonNegative: '거부',
},
);
return granted === PermissionsAndroid.RESULTS.GRANTED;
}
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 1,
staleTime: 30 * 1000,
gcTime: 5 * 60 * 1000,
},
},
});
const Gate: React.FC = () => {
const { state } = useAuth();
const accessToken = state.tokens?.accessToken ?? null;
useEffect(() => {
(async () => {
const ok = await requestLocationPermission();
if (!ok) return;
Geolocation.getCurrentPosition(
pos => {
const { latitude, longitude } = pos.coords;
// 필요하면 저장 (예: AsyncStorage / 전역상태)
AsyncStorage.setItem('lastLat', String(latitude));
AsyncStorage.setItem('lastLon', String(longitude));
},
err => {
console.error(err);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
);
})();
}, []);
if (accessToken) {
AsyncStorage.setItem('accessToken', accessToken);
}
console.log('accesToken', state);
return (
<NavigationContainer
key={accessToken ? 'app' : 'auth'}
ref={navigationRef}
//onReady={updatePrivacyByRoute}
//onStateChange={updatePrivacyByRoute}
>
{accessToken ? <AppStack /> : <AuthStack />}
{/* <LoadingModal /> */}
</NavigationContainer>
);
};
export default function App() {
return (
<SafeAreaProvider>
{/* <JotaiProvider store={store}> */}
<AuthProvider>
<QueryClientProvider client={queryClient}>
<FontLevelProvider>
<Gate />
</FontLevelProvider>
</QueryClientProvider>
</AuthProvider>
{/* </JotaiProvider> */}
</SafeAreaProvider>
);
}