-
Notifications
You must be signed in to change notification settings - Fork 19
/
App.js
120 lines (104 loc) · 3.26 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
import "./wdyr";
import React, { useEffect } from "react";
import { LogBox, Platform, StatusBar, Text } from "react-native";
import * as SplashScreen from "expo-splash-screen";
import AppNavigator from "navigation/AppNavigator";
import { store, persistor } from "store/store";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { SWRConfig } from "swr";
import Toast from "react-native-toast-message";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { BottomSheetModalProvider } from "@gorhom/bottom-sheet";
import { AuthProvider } from "hooks/use-auth";
//import useApp from "hooks/use-app";
import useAppState from "hooks/use-app-state";
import useStyles from "hooks/use-styles";
import useTheme from "hooks/use-theme";
import { toastConfig } from "hooks/use-toast";
//import { AppConstants } from "constants";
import { enableScreens } from "react-native-screens";
enableScreens();
const StyledApp = () => {
// set default text styles
const { globalStyles } = useStyles();
const { isDarkMode } = useTheme();
Text.defaultProps = Text.defaultProps || {};
Text.defaultProps.style = { ...globalStyles.text };
const statusBarContent = isDarkMode ? "light-content" : "dark-content";
return (
<>
<StatusBar
translucent
backgroundColor="transparent"
barStyle={statusBarContent}
/>
<AppNavigator />
</>
);
return <AppNavigator />;
};
const App = () => {
// Initialize the app
//useApp();
// https://github.com/react-navigation/react-navigation/issues/10432#issuecomment-1081942421
useEffect(() => {
if (Platform.OS === "ios") {
enableScreens(false);
}
}, []);
// Dispay splash screen (keep visible until iniital screens ready to render)
useEffect(() => {
try {
(async () => {
await SplashScreen.preventAutoHideAsync();
})();
} catch (e) {
console.warn(e);
}
return;
}, []);
// Persist SWR in-memory cache to device storage on an interval
/*
useEffect(() => {
const interval = setInterval(() => {
console.log(`Persist cache (runs every ${CacheConstants.INTERVAL} ms) -`, new Date());
(async () => {
await persistCache();
})();
}, CacheConstants.INTERVAL);
return () => clearInterval(interval);
}, []);
*/
// Handle App State change(s)
useAppState();
LogBox.ignoreAllLogs();
return (
<>
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<GestureHandlerRootView style={{ flex: 1 }}>
<SWRConfig
value={{
revalidateOnFocus: true,
refreshInterval: 0, //5000, //AppConstants.REFRESH_INTERVAL,
shouldRetryOnError: false,
dedupingInterval: 2000,
focusThrottleInterval: 5000,
loadingTimeout: 10000,
}}
>
<AuthProvider>
<BottomSheetModalProvider>
<StyledApp />
</BottomSheetModalProvider>
</AuthProvider>
</SWRConfig>
</GestureHandlerRootView>
</PersistGate>
</Provider>
<Toast config={toastConfig} />
</>
);
};
export default App;