App.tsx 3.3 KB

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