App.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { NavigationContainer } from '@react-navigation/native';
  2. import AppLoading from 'expo-app-loading';
  3. import 'expo-asset';
  4. import { Asset } from 'expo-asset';
  5. import * as Updates from "expo-updates";
  6. import React, { useEffect, useRef, useState } from 'react';
  7. import { Alert, LogBox, SafeAreaView, StatusBar } from 'react-native';
  8. import 'react-native-gesture-handler';
  9. import { MenuProvider } from 'react-native-popup-menu';
  10. import { SafeAreaProvider } from 'react-native-safe-area-context';
  11. import { QueryClient, QueryClientProvider } from 'react-query';
  12. import { AuthContextProvider } from './src/state/external/auth-provider';
  13. import { PermissionsContextProvider } from './src/state/external/PermissionsContext';
  14. import { navigationRef } from './src/navigation/root-navigator';
  15. import Atlas from './src/presentation/Atlas';
  16. import { colors } from './src/utils/GlobalUtils';
  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/pin-icons/pothole.png'),
  56. require('./assets/pin-icons/roadblock.png'),
  57. require('./assets/pin-icons/barrier.png'),
  58. require('./assets/pin-icons/bump.png'),
  59. require('./assets/pin-icons/information.png'),
  60. require('./assets/pin-icons/washroom.png'),
  61. require('./assets/pin-icons/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;