App.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import 'react-native-gesture-handler';
  2. import React, { useState } from 'react';
  3. import { LogBox, StatusBar, Text } from 'react-native';
  4. import { SafeAreaProvider } from 'react-native-safe-area-context';
  5. import { Asset } from 'expo-asset';
  6. import AppLoading from 'expo-app-loading';
  7. import { QueryClient, QueryClientProvider } from 'react-query';
  8. import {NavigationContainer, navigationRef} from '@react-navigation/native'
  9. import AuthStateProvider from './src/libs/auth/AuthStateProvider'
  10. import { Splash } from './src/components/Splash';
  11. import AuthorizedNavigator from './src/navigation/AuthorizedNavigator';
  12. import UnauthorizedNavigator from './src/navigation/UnauthorizedNavigator';
  13. import { MenuProvider } from 'react-native-popup-menu';
  14. import { colors } from './src/utils/GlobalUtils';
  15. const App = () => {
  16. LogBox.ignoreAllLogs();
  17. const [loading, setLoading] = useState(false);
  18. const _cacheResourcesAsync = async () => {
  19. const images = [
  20. require('./assets/logo-white.png'),
  21. require('./assets/cover-dark.png'),
  22. require('./assets/cover.jpg'),
  23. require('./assets/default-pfp.png'),
  24. require('./assets/pothole.png'),
  25. require('./assets/roadblock.png'),
  26. require('./assets/barrier.png'),
  27. require('./assets/bump.png'),
  28. require('./assets/information.png'),
  29. require('./assets/washroom.png'),
  30. require('./assets/park.png'),
  31. ];
  32. const cacheImages = images.map(image => {
  33. return Asset.fromModule(image).downloadAsync();
  34. });
  35. return Promise.all(cacheImages);
  36. }
  37. const queryClient = new QueryClient()
  38. if (loading) {
  39. return (
  40. <AppLoading
  41. // startAsync={_cacheResourcesAsync}
  42. onFinish={() => setLoading(false)}
  43. onError={console.warn}
  44. />
  45. );
  46. }
  47. return (
  48. <NavigationContainer ref={navigationRef}>
  49. <MenuProvider>
  50. <SafeAreaProvider>
  51. <QueryClientProvider client={queryClient}>
  52. <AuthStateProvider>
  53. {(authenticated, checkingState) =>
  54. <>
  55. <StatusBar barStyle='light-content' backgroundColor={colors.red}/>
  56. {checkingState ?
  57. <Splash/> :
  58. <>
  59. {authenticated ?
  60. <AuthorizedNavigator /> :
  61. <UnauthorizedNavigator /> }
  62. </>}
  63. </>
  64. }
  65. </AuthStateProvider>
  66. </QueryClientProvider>
  67. </SafeAreaProvider>
  68. </MenuProvider>
  69. </NavigationContainer>
  70. );
  71. }
  72. export default App