-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
94 lines (83 loc) · 2.67 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
import NetInfo from "@react-native-community/netinfo";
import { useFonts } from "expo-font";
import React, { useEffect } from "react";
import { Text, TextInput } from "react-native";
import "react-native-gesture-handler";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import Toast from "react-native-toast-message";
import { toastConfig } from "./src/lib/defaultToastConfig";
import { MainNavigator } from "./src/MainNavigator";
import { useNetworkStatus } from "./src/stores/useNetworkStatus";
import { useTaskProgress } from "./src/stores/useTaskProgress";
import {
MD3LightTheme as DefaultTheme,
Provider as PaperProvider,
} from "react-native-paper";
import { colors, fonts } from "./src/constants/AppStyle";
import "./src/lib/firbase";
import { useUserIdStore } from "./src/stores/useUserIdStore";
import { useResultStore } from "./src/stores/useResultStore";
if ((Text as any).defaultProps == null) {
(Text as any).defaultProps = {};
(Text as any).defaultProps.allowFontScaling = false;
}
if ((TextInput as any).defaultProps == null) {
(TextInput as any).defaultProps = {};
(TextInput as any).defaultProps.allowFontScaling = false;
}
export const theme = {
...DefaultTheme,
roundness: 2,
version: 3,
colors: {
...DefaultTheme.colors,
primary: colors["blue-500"],
secondary: colors["green-500"],
tertiary: colors.accent,
primaryContainer: colors["blue-200"],
secondaryContainer: colors["blue-100"],
},
fonts,
};
const App = () => {
const { setConnected } = useNetworkStatus((s) => s);
const { loadTaskProgress } = useTaskProgress((s) => s);
const { loadUserId } = useUserIdStore((s) => s);
const { loadResult } = useResultStore((s) => s);
const [fontsLoaded] = useFonts({
"Inter-Light": require("./src/assets/fonts/Inter-Light.ttf"),
"Inter-Regular": require("./src/assets/fonts/Inter-Regular.ttf"),
"Inter-SemiBold": require("./src/assets/fonts/Inter-SemiBold.ttf"),
});
useEffect(() => {
if (!fontsLoaded) {
loadUserId();
loadTaskProgress();
loadResult();
}
const unsubscribe = NetInfo.addEventListener((state) => {
const { isConnected, isInternetReachable } = state;
//@ts-ignore
setConnected({ isInternetReachable, isConnected });
});
return () => {
unsubscribe();
};
}, []);
if (!fontsLoaded) return null;
return (
<SafeAreaProvider>
<SafeAreaView />
<PaperProvider theme={theme}>
<MainNavigator />
</PaperProvider>
<Toast
config={toastConfig}
onPress={() => Toast.hide()}
visibilityTime={4000}
autoHide
/>
</SafeAreaProvider>
);
};
export default App;