App.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 {createNavigationContainerRef, NavigationContainer,} from '@react-navigation/native'
  9. import AuthStateProvider from './src/libs/auth/AuthStateProvider'
  10. import { LoadingScreen } from './src/components/LoadingScreen';
  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. import { observer } from 'mobx-react';
  16. const App = () => {
  17. const navigationRef = createNavigationContainerRef()
  18. LogBox.ignoreAllLogs();
  19. const [loading, setLoading] = useState(false);
  20. const _cacheResourcesAsync = async () => {
  21. const images = [
  22. require('./assets/logo-white.png'),
  23. require('./assets/cover-dark.png'),
  24. require('./assets/cover.jpg'),
  25. require('./assets/default-pfp.png'),
  26. require('./assets/pothole.png'),
  27. require('./assets/roadblock.png'),
  28. require('./assets/barrier.png'),
  29. require('./assets/bump.png'),
  30. require('./assets/information.png'),
  31. require('./assets/washroom.png'),
  32. require('./assets/park.png'),
  33. ];
  34. const cacheImages = images.map(image => {
  35. return Asset.fromModule(image).downloadAsync();
  36. });
  37. await Promise.all(cacheImages);
  38. }
  39. const queryClient = new QueryClient()
  40. if (loading) {
  41. return (
  42. <AppLoading
  43. startAsync={_cacheResourcesAsync}
  44. onFinish={() => setLoading(false)}
  45. onError={console.warn}
  46. />
  47. );
  48. }
  49. return (
  50. <NavigationContainer ref={navigationRef}>
  51. <MenuProvider>
  52. <SafeAreaProvider>
  53. <QueryClientProvider client={queryClient}>
  54. <StatusBar barStyle='light-content' backgroundColor={colors.red}/>
  55. {/* <AuthStateProvider authenticatedView={<AuthorizedNavigator/>} unauthenticatedView={<UnauthorizedNavigator/>}/> */}
  56. <AuthStateProvider>
  57. {(authenticated, checkingState) =>
  58. <>
  59. <StatusBar barStyle='light-content' backgroundColor={colors.red}/>
  60. {checkingState ?
  61. <LoadingScreen/> :
  62. <>
  63. {authenticated ?
  64. <AuthorizedNavigator /> :
  65. <UnauthorizedNavigator /> }
  66. </>}
  67. </>
  68. }
  69. </AuthStateProvider>
  70. </QueryClientProvider>
  71. </SafeAreaProvider>
  72. </MenuProvider>
  73. </NavigationContainer>
  74. );
  75. }
  76. export default observer(App)