-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
134 lines (114 loc) ยท 3.94 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import {useEffect, useState} from 'react';
import {Linking, DeviceEventEmitter} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import * as RNLocalize from 'react-native-localize';
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import * as amplitude from '@amplitude/analytics-react-native';
import LottieSplashScreen from 'react-native-lottie-splash-screen';
import GlobalNavigation from '@/components/navigation/GlobalNavigation';
import {useThemeStore} from '@/store/useThemeStore';
import i18n from '@/i18n/i18n';
import {useUserStore} from '@/store/useUserStore';
import {trackEvent} from '@/utils/amplitude-utils';
import {AMPLITUDE_API_KEY} from '@env';
import GlobalNavigationUnauthenticated from '@/components/navigation/GlobalNavigationUnauthenticated';
interface AppProps {
sharedURL: string;
}
const queryClient = new QueryClient();
export default function App(props: AppProps) {
const restoreTheme = useThemeStore(state => state.restoreTheme);
const isAuthenticated = useUserStore(state => state.isAuthenticated);
const loadTokens = useUserStore(state => state.loadTokens);
const [isBottomSheetVisible, setIsBottomSheetVisible] = useState(false);
// [iOS & Android] ์ฑ ์ฒซ ์คํ ์ props๋ก sharedURL ์ ๋ฌ
const [sharedURL, setSharedURL] = useState<string>(props.sharedURL || '');
// sharedURL ๋ณ๊ฒฝ ์ ๋ฐํ
์ํธ ๋
ธ์ถ
useEffect(() => {
if (sharedURL) {
setIsBottomSheetVisible(true);
}
}, [sharedURL]);
// [Android] ์ฑ ํฌ๊ทธ๋ผ์ด๋ ์ ํ ์ sharedURL ์ ์ฅ
useEffect(() => {
// URL ๊ณต์ ์ด๋ฒคํธ ๋ฆฌ์ค๋
const urlListener = DeviceEventEmitter.addListener(
'UrlShared',
(url: string) => {
setSharedURL(url);
},
);
// ์ปดํฌ๋ํธ๊ฐ ์ธ๋ง์ดํธ๋ ๋ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ ๊ฑฐ
return () => {
urlListener.remove();
};
}, []);
// [iOS] ์ฑ ํฌ๊ทธ๋ผ์ด๋ ์ ํ ์ sharedURL ์ ์ฅ
useEffect(() => {
if (props.sharedURL) {
setSharedURL(props.sharedURL);
}
const handleDeepLink = (event: {url: string}) => {
const url = event.url;
if (url) {
setSharedURL(url.split('sharedURL=')[1]);
}
};
const linkingListener = Linking.addEventListener('url', handleDeepLink);
Linking.getInitialURL().then(url => {
if (url) handleDeepLink({url});
});
return () => {
linkingListener.remove();
};
}, []);
const initializeApp = async () => {
try {
// ํ
๋ง ๋ณต์
restoreTheme();
// ์ธ์ด ์ค์ -> ์์คํ
์ธ์ด๋ก ๋ณ๊ฒฝ
const locale = RNLocalize.getLocales()[0].languageCode;
if (locale === 'ko') {
i18n.changeLanguage(locale);
} else {
i18n.changeLanguage('en'); // ๊ธฐ๋ณธ ์ธ์ด -> ์์ด
}
// ํ ํฐ ๋ก๋
await loadTokens();
// amplitude ์ด๊ธฐํ
amplitude.init(AMPLITUDE_API_KEY);
// ์ด๋ฒคํธ ์ถ์
trackEvent('App Opened');
} catch (error) {
console.warn('Initialization error:', error);
} finally {
// ๋ชจ๋ ์ด๊ธฐํ ์์
์๋ฃ ํ ์คํ๋์ ํ๋ฉด ์จ๊ธฐ๊ธฐ
LottieSplashScreen.hide();
}
};
useEffect(() => {
initializeApp(); // ์ด๊ธฐํ ํจ์ ํธ์ถ
}, []);
if (isAuthenticated === null) {
return null;
}
return (
<QueryClientProvider client={queryClient}>
<SafeAreaProvider>
<NavigationContainer key={isAuthenticated ? 'auth-true' : 'auth-false'}>
{isAuthenticated ? (
<GlobalNavigation
sharedURL={sharedURL}
setSharedURL={setSharedURL}
isBottomSheetVisible={isBottomSheetVisible}
setIsBottomSheetVisible={setIsBottomSheetVisible}
/>
) : (
<GlobalNavigationUnauthenticated />
)}
</NavigationContainer>
</SafeAreaProvider>
</QueryClientProvider>
);
}