App.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. const App: React.FC = () => {
  16. const updateDismissed = useRef<boolean>(false)
  17. const queryClient = new QueryClient()
  18. useEffect(() => {
  19. if (!__DEV__) {
  20. const timer = setInterval(async () => {
  21. const update = await Updates.checkForUpdateAsync()
  22. if (update.isAvailable && !updateDismissed.current) {
  23. updateDismissed.current = true
  24. setTimeout(() => {
  25. Alert.alert('Update Available', 'An update is available. Would you like to update now?', [
  26. {"text": "Yes", "onPress": async () => {
  27. await Updates.fetchUpdateAsync()
  28. await Updates.reloadAsync()
  29. }},
  30. {"text": "No", "onPress": () => {
  31. Alert.alert('Update Available', 'Update dismissed, you can always revisit it in settings', [
  32. {"text": "OK"}
  33. ])
  34. }}
  35. ])
  36. }, 1000);
  37. }
  38. }, 5000)
  39. return () => clearInterval(timer)
  40. }}, [])
  41. LogBox.ignoreAllLogs();
  42. const [loading, setLoading] = useState(false);
  43. const _cacheResourcesAsync = async () => {
  44. const images = [
  45. require('./assets/logo-white.png'),
  46. require('./assets/cover-dark.png'),
  47. require('./assets/cover.jpg'),
  48. require('./assets/default-pfp.png'),
  49. require('./assets/pothole.png'),
  50. require('./assets/roadblock.png'),
  51. require('./assets/barrier.png'),
  52. require('./assets/bump.png'),
  53. require('./assets/information.png'),
  54. require('./assets/washroom.png'),
  55. require('./assets/park.png'),
  56. ];
  57. const cacheImages = images.map(image => {
  58. return Asset.fromModule(image).downloadAsync();
  59. });
  60. Promise.all(cacheImages);
  61. }
  62. if (loading) {
  63. return (
  64. <AppLoading
  65. startAsync={_cacheResourcesAsync}
  66. onFinish={() => setLoading(false)}
  67. onError={console.warn}
  68. />
  69. );
  70. }
  71. return (
  72. <SafeAreaProvider>
  73. <QueryClientProvider client={queryClient}>
  74. <MenuProvider>
  75. <SafeAreaView style={{height: '100%', backgroundColor: colors.red}}>
  76. <StatusBar barStyle='light-content' backgroundColor={colors.red}/>
  77. <NavigationContainer>
  78. <AuthContextProvider>
  79. <Atlas/>
  80. </AuthContextProvider>
  81. </NavigationContainer>
  82. </SafeAreaView>
  83. </MenuProvider>
  84. </QueryClientProvider>
  85. </SafeAreaProvider>
  86. );
  87. }
  88. export default App;