-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
95 lines (84 loc) · 2.64 KB
/
App.tsx
File metadata and controls
95 lines (84 loc) · 2.64 KB
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
import React from "react";
import { Alert, StatusBar, AsyncStorage } from "react-native";
import { AppLoading } from "expo";
import * as ErrorRecovery from "expo-error-recovery";
import * as Font from "expo-font";
import Constants from "expo-constants";
import { MaterialIcons } from "@expo/vector-icons";
import { createAppContainer } from "react-navigation";
import { RootNavigator } from "./screens";
import { trackNavStateChange } from "./lib/screenTracking";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { MealContextProvider } from "./lib/mealContext";
import * as Sentry from "sentry-expo";
import * as Segment from "expo-analytics-segment";
// Create root app navigator
const AppContainer = createAppContainer(RootNavigator);
// Register Sentry for error reporting
Sentry.init({
dsn: "https://40e9befbb61c4ba9b0e3e2d181fd24f0@sentry.io/1464818",
enableInExpoDevelopment: false
});
if (!__DEV__) {
// Only initialize Segment in prod.
// Avoids warnings in dev.
Segment.initialize({
androidWriteKey: "vHomtRC0DwAPbwS0ztqljf2tUmgrdy19",
iosWriteKey: "GIwWSlcucci2UYi1eEHyyBqHqM9X7g33"
});
Segment.identify(Constants.installationId);
console.log("segment: initialized");
} else {
console.log("segment: not initializing in dev mode");
}
export default class App extends React.Component {
state = { ready: false };
crashed: boolean = false;
constructor(props: any) {
super(props);
// @ts-ignore
const { exp } = this.props;
if (exp.errorRecovery && exp.errorRecovery.didCrash) {
this.crashed = true;
}
ErrorRecovery.setRecoveryProps({ didCrash: true });
}
private async loadResources(this: any) {
// Reset storage on crash
if (this.crashed) {
if (!__DEV__) {
Alert.alert(
"Issue reported",
"Cookie just closed unexpectedly.\n\nThis issue has been reported to the developers, and the app has been reset to (hopefully) working condition."
);
} else {
console.log("App.tsx: cleared AsyncStorage on crash");
}
await AsyncStorage.clear();
}
// Load all fonts and assets
await Font.loadAsync({
...MaterialIcons.font
});
}
render() {
const { ready } = this.state;
if (ready) {
return (
<>
<SafeAreaProvider>
<MealContextProvider>
<AppContainer onNavigationStateChange={trackNavStateChange} />
</MealContextProvider>
</SafeAreaProvider>
</>
);
}
return (
<AppLoading
startAsync={this.loadResources.bind(this)}
onFinish={() => this.setState({ ready: true })}
/>
);
}
}