-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
114 lines (101 loc) · 3.73 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { setPositionAsync, setBackgroundColorAsync } from "expo-navigation-bar";
import { ToastManager, BottomSheetManager, ModalManager } from "@/Components";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { Animated, BackHandler, StatusBar } from "react-native";
import { useBottomSheet, useOptions, useTheme } from "@/hooks";
import { NavigationContainer } from "@react-navigation/native";
import { useMediaLibraryPermissions } from "expo-image-picker";
import { init, getCurrentScope } from "@sentry/react-native";
import { enableScreens } from "react-native-screens";
import { useCallback, useEffect, useRef, useState } from "react";
import { getItem, isAndroid } from "@/utils";
import { Navigation } from "@/Navigation";
import { useFonts } from "expo-font";
import { Splash } from "@/Screens";
init({
dsn: "https://69af4e84f735adb3673a42550260e390@o4507229156474880.ingest.us.sentry.io/4507229158113280",
});
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 3,
staleTime: 1000 * 60 * 2,
refetchOnWindowFocus: false,
},
},
});
export default function App() {
enableScreens(true);
const [fontsLoaded] = useFonts({
Medium: require("./app/assets/font/Medium.ttf"),
Regular: require("./app/assets/font/Regular.ttf"),
SemiBold: require("./app/assets/font/SemiBold.ttf"),
});
const fade = useRef(new Animated.Value(1)).current;
const [status, requestPermission] = useMediaLibraryPermissions();
const { getTheme, load: loadTheme } = useTheme();
const { close, isOpened } = useBottomSheet();
const { load: loadOptions } = useOptions();
const [token, setToken] = useState<null | undefined | string>(undefined);
const [splash, setSplash] = useState(true);
const tokenPromise = useCallback(
() =>
new Promise(async (resolve) => {
const accessToken = await getItem("access_token");
setToken(accessToken);
const userData = await getItem("user_data");
const [id, username] = userData ? userData.split("||") : [undefined, undefined];
getCurrentScope().setUser({ id: id || "알 수 없음", username: username || "알 수 없음" });
resolve("test");
}).then(() =>
setTimeout(
() =>
Animated.timing(fade, { toValue: 0, duration: 300, useNativeDriver: false }).start(() =>
setSplash(false)
),
1500
)
),
[]
);
useEffect(() => {
tokenPromise();
if (isAndroid) {
setPositionAsync("absolute");
setBackgroundColorAsync("#ffffff01");
}
loadTheme();
loadOptions();
if (!status?.granted) requestPermission();
}, []);
useEffect(() => {
const handleClose = () => {
close();
return isOpened;
};
BackHandler.addEventListener("hardwareBackPress", handleClose);
return () => BackHandler.removeEventListener("hardwareBackPress", handleClose);
}, [isOpened]);
return (
<QueryClientProvider client={queryClient}>
<GestureHandlerRootView>
<SafeAreaProvider>
<NavigationContainer>
<StatusBar
translucent
backgroundColor="transparent"
barStyle={getTheme() === "dark" ? "light-content" : "dark-content"}
/>
{fontsLoaded && token !== undefined && <Navigation token={token} />}
{splash && <Splash fade={fade} />}
<ToastManager />
<ModalManager />
<BottomSheetManager />
</NavigationContainer>
</SafeAreaProvider>
</GestureHandlerRootView>
</QueryClientProvider>
);
}