-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
134 lines (122 loc) · 3.19 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
132
133
134
import EXAppLoading from "expo-app-loading";
import { useFonts } from "expo-font";
import React from "react";
import { ScrollView, StyleSheet, Text, View } from "react-native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import GameProvider from "./context/GameProvider";
import GameScreen from "./screens/GameScreen";
import AudioManager from "./src/AudioManager";
import { useResolvedValue } from "./src/hooks/useResolvedValue";
import ModelLoader from "./src/ModelLoader";
import LoadingScreen from "./screens/LoadingScreen";
console.ignoredYellowBox = [
"WebGL",
"THREE.WebGLRenderer",
"THREE.WebGLProgram",
];
export default function App() {
const [isLoading, setIsLoading] = React.useState(true);
return (
<>
<AssetLoading setIsLoading={setIsLoading}>
<SafeAreaProvider>
<GameProvider>
<GameScreen />
</GameProvider>
</SafeAreaProvider>
</AssetLoading>
<LoadingScreen isLoading={isLoading}></LoadingScreen>
</>
);
}
function AssetLoading({ setIsLoading, children }) {
const [fontLoaded] = useFonts({
retro: require("./assets/fonts/retro.ttf"),
});
const [audioLoaded, audioLoadingError] = useResolvedValue(() =>
AudioManager.setupAsync()
);
const [modelsLoaded, modelLoadingError] = useResolvedValue(() =>
ModelLoader.loadModels()
);
console.log("Loading:", {
fonts: fontLoaded,
audio: audioLoaded,
models: modelsLoaded,
});
React.useEffect(() => {
if (modelsLoaded && fontLoaded && audioLoaded) {
setIsLoading(false);
}
}, [modelsLoaded, fontLoaded, audioLoaded]);
if (modelLoadingError) {
return (
<ErrorScreen
message={modelLoadingError.message}
stack={modelLoadingError.stack}
/>
);
}
if (audioLoadingError) {
return (
<ErrorScreen
message={audioLoadingError.message}
stack={audioLoadingError.stack}
/>
);
}
if (modelsLoaded && fontLoaded && audioLoaded) {
return children;
}
return <EXAppLoading />;
}
const ErrorScreen = ({ message, stack }) => (
<View style={styles.errorContainer}>
<ScrollView style={styles.error} contentContainerStyle={{}}>
<Text style={styles.errorTitle}>This is a fatal error 👋 </Text>
<Text style={styles.errorText}>{message}</Text>
{stack && (
<Text
style={[
styles.errorText,
{ fontSize: 12, opacity: 0.8, marginTop: 4 },
]}
>
{stack}
</Text>
)}
</ScrollView>
</View>
);
const styles = StyleSheet.create({
splash: {
backgroundColor: "#87C6FF",
resizeMode: "contain",
},
errorContainer: {
...StyleSheet.absoluteFillObject,
flex: 1,
backgroundColor: "black",
justifyContent: "center",
alignItems: "center",
},
error: {
maxWidth: 300,
maxHeight: "50%",
borderRadius: 8,
paddingVertical: 16,
paddingHorizontal: 24,
backgroundColor: "#9e0000",
},
errorTitle: {
fontSize: 30,
color: "white",
fontWeight: "bold",
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: "rgba(0,0,0,0.1)",
},
errorText: {
fontSize: 24,
color: "white",
},
});