forked from kakada/react_native_baseline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.android.js
120 lines (102 loc) · 3.61 KB
/
App.android.js
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useEffect, useRef, useState } from 'react';
import type {Node} from 'react';
import { StatusBar, Text, AppState, Alert, View } from 'react-native';
import SplashScreen from 'react-native-splash-screen';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Sentry from "@sentry/react-native";
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
import {useTranslation} from 'react-i18next';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {BottomSheetModalProvider} from '@gorhom/bottom-sheet';
import FeatherIcon from 'react-native-vector-icons/Feather';
import AppNavigator from './app/navigators/app_navigator';
import i18nextInit from './app/localizations/i18next';
import color from './app/themes/color';
import { FontFamily } from './app/themes/font';
import { environment } from './app/config/environment';
import appVisitService from './app/services/app_visit_service'
import systemBackButtonHelper from './app/helpers/system_back_button_helper';
import seedDataService from './app/services/seed_data_service';
import notificationService from './app/services/notification_service';
import { store } from './app/store'
import { Provider } from 'react-redux'
import { navigationRef } from './app/navigators/app_navigator';
import NotifService from './app/services/NotifService';
import useInAppUpdate from './app/hooks/useInAppUpdate';
Sentry.init({
dsn: environment.sentryDSN,
});
i18nextInit();
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
primary: color.primaryColor,
},
fonts: {
...DefaultTheme.fonts,
regular: { fontFamily: FontFamily.regular },
}
};
Text.defaultProps = Text.defaultProps || {};
Text.defaultProps.allowFontScaling = false;
const App: () => Node = () => {
const {t, i18n} = useTranslation();
let backHandler = null;
const appState = useRef(AppState.currentState);
const [appStateVisible, setAppStateVisible] = useState(appState.current);
const notif = new NotifService((token) => {}, (notif) => {});
useInAppUpdate();
useEffect(() => {
setDefaultLocale();
SplashScreen.hide();
notificationService.onNotificationOpenedApp(() => navigationRef.current?.navigate('NotificationView'));
seedDataService.seedToRealm();
appVisitService.recordVisit();
backHandler = systemBackButtonHelper.handleBackToExitApp(t('pressBackTwiceToExitTheApp'));
const subscription = AppState.addEventListener("change", nextAppState => {
if (
appState.current.match(/inactive|background/) && nextAppState === "active"
) {
notif.cancelAll();
}
appState.current = nextAppState;
setAppStateVisible(appState.current);
});
return () => {
backHandler.remove();
subscription.remove();
};
}, []);
const setDefaultLocale = async () => {
const selectedLanguage = await AsyncStorage.getItem('APP_LANGUAGE')
i18n.changeLanguage(selectedLanguage);
}
return (
<React.Fragment>
<Provider store={store}>
<PaperProvider
settings={{
icon: props => <FeatherIcon {...props} />
}}
theme={theme}
>
<GestureHandlerRootView style={{flex: 1}}>
<BottomSheetModalProvider>
<StatusBar barStyle={'light-content'} />
<AppNavigator/>
</BottomSheetModalProvider>
</GestureHandlerRootView>
</PaperProvider>
</Provider>
</React.Fragment>
);
};
export default App;