-
Notifications
You must be signed in to change notification settings - Fork 34
/
App.tsx
219 lines (192 loc) · 5.99 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import React, { Component } from 'react';
import {
BackHandler,
Platform,
Linking,
UIManager,
AppState,
AppStateStatus,
NativeEventSubscription,
EmitterSubscription,
} from 'react-native';
import { KeyboardProvider } from 'react-native-keyboard-controller';
import { Provider, observer } from 'mobx-react';
import { setup } from 'react-native-iap';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { NavigationContainer } from '@react-navigation/native';
// import ShareMenu from 'react-native-share-menu';
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
import { PortalProvider } from '@gorhom/portal';
import { focusManager } from '@tanstack/react-query';
// we import the service provider first & register the services
import sp from '~/services/serviceProvider';
import '~/services/servicesRegister';
import { IS_IPAD } from '~/config/Config';
import NavigationStack from './src/navigation/NavigationStack';
import { getStores } from './AppStores';
import './AppErrors';
import './src/common/services/socket.service';
import ErrorBoundary from './src/common/components/ErrorBoundary';
import { StoresProvider } from './src/common/hooks/use-stores';
import appInitManager from './AppInitManager';
import AppMessageProvider from 'AppMessageProvider';
import * as SplashScreen from 'expo-splash-screen';
import FriendlyCaptchaProvider, {
setFriendlyCaptchaReference,
} from '~/common/components/friendly-captcha/FriendlyCaptchaProvider';
import { Orientation, QueryProvider } from '~/services';
import { ConfigProvider } from '~/modules/livepeer';
import { FontsLoader } from 'FontsLoader';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();
appInitManager.initializeServices();
// Setup apple IAP to use storekit 2
setup({ storekitMode: 'STOREKIT2_MODE' });
if (
Platform.OS === 'android' &&
UIManager.setLayoutAnimationEnabledExperimental
) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
type Props = {};
export let APP_CONST = {
realScreenHeight: 0,
};
/**
* App
*/
@observer
class App extends Component<Props> {
shareReceiveSubscription;
constructor(
props,
private disposeLinkSubscription?: EmitterSubscription,
private stateSubscription?: NativeEventSubscription,
private backHandlerSubscription?: NativeEventSubscription,
) {
super(props);
if (IS_IPAD) {
Orientation.unlock();
} else {
Orientation.lockPortrait();
}
}
/**
* On component did mount
*/
componentDidMount() {
// Register event listeners
this.backHandlerSubscription = BackHandler.addEventListener(
'hardwareBackPress',
this.onBackPress,
);
this.disposeLinkSubscription = Linking.addEventListener(
'url',
this.handleOpenURL,
);
// send focus states to react query
this.stateSubscription = AppState.addEventListener(
'change',
(status: AppStateStatus) => {
focusManager.setFocused(status === 'active');
},
);
}
/**
* On component will unmount
*/
componentWillUnmount() {
this.stateSubscription?.remove();
this.disposeLinkSubscription?.remove();
this.backHandlerSubscription?.remove();
this.shareReceiveSubscription?.remove();
}
/**
* Handle hardware back button
*/
onBackPress = () => {
try {
sp.navigation.goBack();
return false;
} catch (err) {
return true;
}
};
/**
* Handle deeplink urls
*/
handleOpenURL = event => {
if (event.url) {
// the var can be cleaned so we check again
setTimeout(() => {
sp.resolve('deepLinks').navigate(event.url, true);
event.url = '';
}, 100);
}
};
report(...data) {
console.log(data);
}
/**
* Render
*/
render() {
const styles = sp.styles;
// App not shown until the theme is loaded
if (styles.theme === -1) {
return null;
}
const stores = getStores();
return (
<KeyboardProvider>
<FontsLoader>
<GestureHandlerRootView style={appContainerStyle}>
<SafeAreaProvider>
{sp.session.ready && (
<StoresProvider>
<QueryProvider>
<Provider key="app" {...stores}>
<NavigationContainer
ref={sp.navigation.navigationRef}
theme={styles.navTheme}
onReady={appInitManager.onNavigatorReady}
onStateChange={sp.navigation.onStateChange}>
<AppMessageProvider key={`message_${styles.theme}`}>
<FriendlyCaptchaProvider
ref={setFriendlyCaptchaReference}>
<PortalProvider>
<BottomSheetModalProvider>
<ErrorBoundary
message="An error occurred"
containerStyle={styles.style.centered}>
<ConfigProvider>
<NavigationStack
key={styles.theme + sp.i18n.locale}
/>
</ConfigProvider>
</ErrorBoundary>
</BottomSheetModalProvider>
</PortalProvider>
</FriendlyCaptchaProvider>
</AppMessageProvider>
</NavigationContainer>
</Provider>
</QueryProvider>
</StoresProvider>
)}
</SafeAreaProvider>
</GestureHandlerRootView>
</FontsLoader>
</KeyboardProvider>
);
}
}
export default App;
const appContainerStyle = sp.styles.combine(
'flexContainer',
'bgPrimaryBackground',
);
// if (__DEV__) {
// require('./tron');
// }