forked from ngocle2497/RNChallenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
48 lines (46 loc) · 1.61 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
import { AppNavigation } from '@navigation/AppNavigation'
import React, { memo, Suspense, useEffect, useState } from 'react'
import isEqual from 'react-fast-compare';
import I18n from '@utils/i18n/i18n'
import { I18nextProvider } from 'react-i18next';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { View } from 'react-native';
import codePush from 'react-native-code-push';
const AppComponent = () => {
const [updating, setUpdating] = useState(true);
const checkUpdate = async () => {
await codePush.sync(
{ installMode: codePush.InstallMode.ON_NEXT_RESTART },
status => {
switch (status) {
case codePush.SyncStatus.INSTALLING_UPDATE:
setUpdating(true);
break;
case codePush.SyncStatus.UP_TO_DATE:
setUpdating(false);
break;
default:
setUpdating(false);
}
},
);
};
useEffect(() => {
checkUpdate();
}, []);
return updating ? null : (
<SafeAreaProvider>
<I18nextProvider i18n={I18n}>
<Suspense fallback={<View />}>
<AppNavigation />
</Suspense>
</I18nextProvider>
</SafeAreaProvider>
)
}
const codePushOption = {
checkFrequency: codePush.CheckFrequency.ON_APP_START,
installMode: codePush.InstallMode.ON_NEXT_RESTART,
};
export const App = memo(AppComponent, isEqual)
export const MyApp = codePush(codePushOption)(App);