-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
135 lines (121 loc) · 4.13 KB
/
App.tsx
File metadata and controls
135 lines (121 loc) · 4.13 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
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
// Polyfills — must be imported before anything else
import 'react-native-get-random-values';
import { Buffer } from 'buffer';
(globalThis as any).Buffer = Buffer;
import React, { useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { StyleSheet } from 'react-native';
import { WalletScreen } from './src/screens/WalletScreen';
import { SetupScreen } from './src/screens/SetupScreen';
import { GameScreen } from './src/screens/GameScreen';
import { ResultScreen } from './src/screens/ResultScreen';
import { LeaderboardScreen } from './src/screens/LeaderboardScreen';
import { InGameWalletScreen } from './src/screens/InGameWalletScreen';
import { initAudio, unloadAllSounds } from './src/utils/audio';
import { Colors } from './src/theme';
import { AppModalProvider } from './src/components/AppModal';
// -------------------------------------------
// Navigation param types
// -------------------------------------------
export type RootStackParamList = {
Wallet: undefined;
InGameWallet: undefined;
Setup: undefined;
Game: undefined;
Result: undefined;
Leaderboard: undefined;
};
const Stack = createNativeStackNavigator<RootStackParamList>();
import * as SplashScreen from 'expo-splash-screen';
// Keep the splash screen visible while we fetch resources
void SplashScreen.preventAutoHideAsync().catch(() => {
// Ignore if splash is already controlled by the host environment (e.g., Expo Go).
});
export default function App() {
const [appIsReady, setAppIsReady] = React.useState(false);
useEffect(() => {
async function prepare() {
try {
// Initialize audio without blocking app startup forever.
await Promise.race([
initAudio(),
new Promise((resolve) => setTimeout(resolve, 1200)),
]);
// Artificial delay for smooth splash screen branding visibility
await new Promise((resolve) => setTimeout(resolve, 800));
} catch (e) {
console.warn(e);
} finally {
// Tell the application to render
setAppIsReady(true);
}
}
prepare();
return () => {
unloadAllSounds();
};
}, []);
useEffect(() => {
if (appIsReady) {
SplashScreen.hideAsync().catch(() => {
// Prevent startup deadlock if splash API fails in Expo Go.
});
}
}, [appIsReady]);
if (!appIsReady) {
return null;
}
return (
<GestureHandlerRootView style={styles.root}>
<AppModalProvider>
<NavigationContainer
theme={{
dark: true,
colors: {
primary: Colors.neonBlue,
background: Colors.bg,
card: Colors.bgCard,
text: Colors.textPrimary,
border: Colors.border,
notification: Colors.neonPurple,
},
fonts: {
regular: { fontFamily: 'System', fontWeight: '400' },
medium: { fontFamily: 'System', fontWeight: '500' },
bold: { fontFamily: 'System', fontWeight: '700' },
heavy: { fontFamily: 'System', fontWeight: '900' },
},
}}
>
<Stack.Navigator
initialRouteName="Wallet"
screenOptions={{
headerShown: false,
animation: 'fade',
contentStyle: { backgroundColor: Colors.bg },
}}
>
<Stack.Screen name="Wallet" component={WalletScreen} />
<Stack.Screen name="InGameWallet" component={InGameWalletScreen} />
<Stack.Screen name="Setup" component={SetupScreen} />
<Stack.Screen
name="Game"
component={GameScreen}
options={{ gestureEnabled: false }}
/>
<Stack.Screen name="Result" component={ResultScreen} />
<Stack.Screen name="Leaderboard" component={LeaderboardScreen} />
</Stack.Navigator>
</NavigationContainer>
</AppModalProvider>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: Colors.bg,
},
});