App.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React, { useEffect, useRef, useState } from 'react';
  2. import { Alert, LogBox, SafeAreaView, StatusBar } from 'react-native';
  3. import 'react-native-gesture-handler';
  4. import { SafeAreaProvider } from 'react-native-safe-area-context';
  5. import Atlas from './src/components/Atlas';
  6. import 'expo-asset';
  7. import AppLoading from 'expo-app-loading';
  8. import * as Updates from "expo-updates";
  9. import { Asset } from 'expo-asset';
  10. import { MenuProvider } from 'react-native-popup-menu';
  11. import { createNavigationContainerRef, NavigationContainer } from '@react-navigation/native';
  12. import { colors } from './src/utils/GlobalUtils';
  13. import { AuthContextProvider } from './src/data/Auth/AuthContext';
  14. import { QueryClient, QueryClientProvider, useQueryClient } from 'react-query';
  15. import { navigationRef } from './src/navigation/RootNavigator';
  16. import { PermissionsContextProvider } from './src/data/PermissionsContext';
  17. import { LOGGING } from './src/utils/logging';
  18. const App: React.FC = () => {
  19. const updateDismissed = useRef<boolean>(false)
  20. const queryClient = new QueryClient()
  21. useEffect(() => {
  22. LOGGING.log("SYSTEM", 'info', "Launching app...")
  23. if (!__DEV__) {
  24. LOGGING.log("SYSTEM", 'info', "App is release version, checking for updates...")
  25. const timer = setInterval(async () => {
  26. const update = await Updates.checkForUpdateAsync()
  27. if (update.isAvailable && !updateDismissed.current) {
  28. LOGGING.log("SYSTEM", 'info', "Update available, prompting user...")
  29. updateDismissed.current = true
  30. setTimeout(() => {
  31. Alert.alert('Update Available', 'An update is available. Would you like to update now?', [
  32. {"text": "Yes", "onPress": async () => {
  33. await Updates.fetchUpdateAsync()
  34. await Updates.reloadAsync()
  35. }},
  36. {"text": "No", "onPress": () => {
  37. Alert.alert('Update Available', 'Update dismissed, you can always revisit it in settings', [
  38. {"text": "OK"}
  39. ])
  40. }}
  41. ])
  42. }, 1000);
  43. }
  44. }, 5000)
  45. return () => clearInterval(timer)
  46. }}, [])
  47. LogBox.ignoreAllLogs();
  48. const [loading, setLoading] = useState(false);
  49. const _cacheResourcesAsync = async () => {
  50. const images = [
  51. require('./assets/logo-white.png'),
  52. require('./assets/cover-dark.png'),
  53. require('./assets/cover.jpg'),
  54. require('./assets/default-pfp.png'),
  55. require('./assets/pothole.png'),
  56. require('./assets/roadblock.png'),
  57. require('./assets/barrier.png'),
  58. require('./assets/bump.png'),
  59. require('./assets/information.png'),
  60. require('./assets/washroom.png'),
  61. require('./assets/park.png'),
  62. ];
  63. const cacheImages = images.map(image => {
  64. return Asset.fromModule(image).downloadAsync();
  65. });
  66. Promise.all(cacheImages);
  67. }
  68. if (loading) {
  69. return (
  70. <AppLoading
  71. startAsync={_cacheResourcesAsync}
  72. onFinish={() => setLoading(false)}
  73. onError={console.warn}
  74. />
  75. );
  76. }
  77. return (
  78. <SafeAreaProvider>
  79. <QueryClientProvider client={queryClient}>
  80. <MenuProvider>
  81. <SafeAreaView style={{height: '100%', backgroundColor: colors.red}}>
  82. <StatusBar barStyle='light-content' backgroundColor={colors.red}/>
  83. <NavigationContainer ref={navigationRef}>
  84. <AuthContextProvider>
  85. <PermissionsContextProvider>
  86. <Atlas/>
  87. </PermissionsContextProvider>
  88. </AuthContextProvider>
  89. </NavigationContainer>
  90. </SafeAreaView>
  91. </MenuProvider>
  92. </QueryClientProvider>
  93. </SafeAreaProvider>
  94. );
  95. }
  96. export default App;