forked from BetterSocial/mobileapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
131 lines (115 loc) · 3.82 KB
/
App.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
121
122
123
124
125
126
127
128
129
130
131
import {HumanIDProvider} from '@human-internet/react-native-humanid';
import {NavigationContainer} from '@react-navigation/native';
import * as React from 'react';
import Toast from 'react-native-toast-message';
import {BackHandler, View, KeyboardAvoidingView, Platform} from 'react-native';
import FlashMessage from 'react-native-flash-message';
import {
SafeAreaProvider,
useSafeAreaFrame,
useSafeAreaInsets
} from 'react-native-safe-area-context';
import {RecoilRoot} from 'recoil';
import {OverlayProvider, Streami18n} from 'stream-chat-react-native';
import {RecoilDebugObserver} from 'reactotron-recoil-plugin';
import {reactotronInstance} from './src/libraries/reactotron/reactotronInstance';
import Store from './src/context/Store';
import {linking} from './src/navigations/linking';
import {RootNavigator} from './src/navigations/root-stack';
import {fetchRemoteConfig} from './src/utils/FirebaseUtil';
import {toastConfig} from './src/configs/ToastConfig';
import {Analytics} from './src/libraries/analytics/firebaseAnalytics';
const App = () => {
const {bottom, top} = useSafeAreaInsets();
const {height} = useSafeAreaFrame();
const streami18n = new Streami18n({
language: 'en'
});
const navigationRef = React.useRef();
const routeNameRef = React.useRef();
React.useEffect(() => {
const init = async () => {
try {
fetchRemoteConfig();
} catch (error) {
if (__DEV__) {
console.log('app ', error);
}
}
};
init();
// return unsubscribe;
}, []);
const preventCloseApp = () => true;
const backFunc = () => {
navigationRef.current.goBack();
return true;
};
const handleStateChange = () => {
const isCanBack = navigationRef.current.canGoBack();
if (!isCanBack) {
BackHandler.removeEventListener('hardwareBackPress', backFunc);
BackHandler.addEventListener('hardwareBackPress', preventCloseApp);
} else {
BackHandler.removeEventListener('hardwareBackPress', preventCloseApp);
BackHandler.addEventListener('hardwareBackPress', backFunc);
}
// log event
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef.current?.getCurrentRoute?.()?.name;
if (currentRouteName && previousRouteName !== currentRouteName) {
Analytics.trackingScreen(currentRouteName);
}
if (__DEV__) {
console.log('current screen name: ', currentRouteName);
console.tron.log('current screen name: ', currentRouteName);
}
routeNameRef.current = currentRouteName;
};
const onReadyState = () => {
if (navigationRef.current) {
routeNameRef.current = navigationRef.current?.getCurrentRoute?.()?.name;
}
};
return (
<>
<HumanIDProvider />
{/* <RealmProvider> */}
<RecoilRoot>
{__DEV__ ? <RecoilDebugObserver instance={reactotronInstance} /> : null}
<Store>
<NavigationContainer
onReady={onReadyState}
onStateChange={handleStateChange}
ref={navigationRef}
linking={linking}>
<View style={{paddingTop: top, paddingBottom: bottom}}>
<OverlayProvider bottomInset={bottom} i18nInstance={streami18n}>
<KeyboardAvoidingView enabled={Platform.OS === 'ios'} behavior="padding">
<RootNavigator areaHeight={height} />
</KeyboardAvoidingView>
</OverlayProvider>
</View>
</NavigationContainer>
</Store>
</RecoilRoot>
{/* </RealmProvider> */}
<Toast config={toastConfig} />
<FlashMessage position="top" />
</>
);
};
const RootApp = () => (
<SafeAreaProvider
initialMetrics={{
insets: {
top: 0,
right: 0,
bottom: 0,
left: 0
}
}}>
<App />
</SafeAreaProvider>
);
export default RootApp;