-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.tsx
107 lines (96 loc) · 3.36 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
/* eslint-disable @typescript-eslint/no-var-requires */
//#region Import Modules
import AppLoading from "expo-app-loading";
import { Asset } from "expo-asset";
import * as Font from "expo-font";
import * as Localization from "expo-localization";
import React from "react";
import { Platform, StatusBar } from "react-native";
import { Provider as ReduxProvider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { Container } from "./src/components";
import { UpdateSnackBar } from "./src/components/atoms";
import { Message } from "./src/constants";
import { AuroraManagerInstance, SoundManagerInstance } from "./src/managers";
import { InitialNavigator } from "./src/navigation";
import reduxStore from "./src/store";
//#endregion
//#region Types
type AppProps = {
skipLoadingScreen: boolean;
};
type AppState = {
isLoadingComplete: boolean;
};
//#endregion
//#region Component
export default class App extends React.Component<AppProps, AppState> {
public state = {
isLoadingComplete: false,
};
constructor(props: AppProps) {
super(props);
}
public componentDidMount(): void {
Message.setLocale(Localization.locale);
}
public render(): JSX.Element {
const persistedRedux = reduxStore();
if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
return (
<AppLoading
startAsync={this.loadResourcesAsync}
onError={this.handleLoadingError}
onFinish={this.handleFinishLoading}
/>
);
} else {
return (
<ReduxProvider store={persistedRedux.store}>
<PersistGate
loading={undefined}
persistor={persistedRedux.persistor}
>
<Container>
{Platform.OS === "ios" && (
<StatusBar barStyle="default" />
)}
<InitialNavigator></InitialNavigator>
<UpdateSnackBar></UpdateSnackBar>
</Container>
</PersistGate>
</ReduxProvider>
);
}
}
//#endregion
//#region Function
public loadResourcesAsync = async (): Promise<void> => {
Promise.all([
Font.loadAsync({
calibre_app_regular: require("./assets/fonts/calibre_app_regular.ttf"),
calibre_app_semibold: require("./assets/fonts/calibre_app_semibold.ttf"),
}),
Asset.loadAsync([
require("./assets/profiles/default_profile_content.ttf"),
]),
SoundManagerInstance.loadResource(),
]);
return;
};
public handleLoadingError = (error: Error): void => {
// In this case, you might want to report the error to your error
// reporting service, for example Sentry
// tslint:disable-next-line:no-console
console.warn(error);
};
public handleFinishLoading = (): void => {
if (Platform.OS === "web") {
AuroraManagerInstance.setAuroraSound(
SoundManagerInstance.getData()
);
}
this.setState({ isLoadingComplete: true });
};
//#endregion
}