-
Notifications
You must be signed in to change notification settings - Fork 4
/
App.tsx
91 lines (84 loc) · 2.84 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
import "react-native-gesture-handler";
import analytics from "@react-native-firebase/analytics";
import crashlytics from "@react-native-firebase/crashlytics";
import eventsReducer from "./store/reducers/events";
import useCachedResources from "./hooks/useCachedResources";
import useColorScheme from "./hooks/useColorScheme";
import Colors from "./constants/Colors";
import React, { useEffect } from "react";
import Navigation from "./navigation";
import ReduxThunk from "redux-thunk";
import { applyMiddleware, createStore, combineReducers } from "redux";
import { init } from "./helpers/sqlite_db";
import { useNetInfo, NetInfoState } from "@react-native-community/netinfo";
import { Alert, StyleSheet } from "react-native";
import { ColorSchemeName } from "react-native";
import { StatusBar } from "expo-status-bar";
import { ActivityIndicator, MD3DarkTheme, Provider as PaperProvider } from "react-native-paper";
import { Provider as StoreProvider } from "react-redux";
import { View } from "./components/Themed";
init()
.then(() => {
analytics().logEvent("custom_log", {
description: "--- Analytics: App -> init -> then",
});
})
.catch((error: unknown) => {
if (error instanceof Error) {
analytics().logEvent("custom_log", {
description: "--- Analytics: App -> init -> catch, error: " + error,
});
crashlytics().recordError(error);
}
}).finally(() => {
analytics().logEvent("custom_log", {
description: "--- Analytics: App -> init -> finally",
});
});
const rootReducer = combineReducers({
events: eventsReducer,
});
const store = createStore(rootReducer, applyMiddleware(ReduxThunk));
export default function App() {
const colorScheme: ColorSchemeName = useColorScheme();
const internetState: NetInfoState = useNetInfo();
const isLoadingComplete: boolean = useCachedResources();
useEffect(() => {
if (internetState.isConnected === false) {
Alert.alert(
"No Internet! ❌",
"Sorry, we need an Internet connection for TamoTam to run correctly.",
[{ text: "Okay" }]
);
}
analytics().logEvent("custom_log", {
description: "--- Analytics: App -> useEffect[internetState.isConnected]: " + internetState.isConnected,
});
}, [internetState.isConnected]);
if (!isLoadingComplete) {
return (
<View style={styles.centered}>
<ActivityIndicator
color={colorScheme === "dark" ? Colors.dark.text : Colors.light.text}
size="large"
/>
</View>
);
} else {
return (
<StoreProvider store={store}>
<PaperProvider theme={MD3DarkTheme}>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</PaperProvider>
</StoreProvider>
);
}
}
const styles = StyleSheet.create({
centered: {
alignItems: "center",
flex: 1,
justifyContent: "center",
},
});