-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
75 lines (61 loc) · 2.41 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
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Sentry from '@sentry/react-native';
import { useFonts } from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import React, { useCallback, useEffect, useRef } from 'react';
import { AppState, StyleSheet } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { MainApp } from './src';
import { auth } from './src/auth';
import { fontConfig, namespace, secrets } from './src/config';
import { SUE_REPORT_VALUES } from './src/screens';
const sentryApi = secrets[namespace]?.sentryApi;
if (sentryApi?.dsn) {
Sentry.init({
dsn: sentryApi.dsn,
enabled: !__DEV__ // NOTE: Sentry will be enabled only in production by default
// debug: __DEV__ // NOTE: If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event.
});
}
// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();
const App = () => {
const appState = useRef(AppState.currentState);
const [isFontLoaded] = useFonts(fontConfig);
useEffect(() => {
// runs auth() if app returns from background or inactive to foreground
const subscription = AppState.addEventListener('change', (nextAppState) => {
if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
auth();
}
appState.current = nextAppState;
});
return () => {
subscription.remove();
};
}, []);
const onLayoutRootView = useCallback(async () => {
if (isFontLoaded) {
// when the application is closed and reopened, the saved data in the sue report form is deleted
await AsyncStorage.removeItem(SUE_REPORT_VALUES);
// This tells the splash screen to hide immediately! If we call this after
// `isFontLoaded`, then we may see a blank screen while the app is
// loading its initial state and rendering its first pixels. So instead,
// we hide the splash screen once we know the root view has already
// performed layout.
await SplashScreen.hideAsync();
}
}, [isFontLoaded]);
if (!isFontLoaded) return null;
return (
<GestureHandlerRootView style={styles.flex} onLayout={onLayoutRootView}>
<MainApp />
</GestureHandlerRootView>
);
};
export default Sentry.wrap(App);
const styles = StyleSheet.create({
flex: {
flex: 1
}
});