1- import React , { useState } from "react" ;
1+ import React , { useCallback , useEffect , useState } from "react" ;
22import { Image } from "react-native" ;
3- import AppLoading from "expo-app-loading " ;
4- import { useFonts } from '@use- expo/ font' ;
3+ import * as SplashScreen from "expo-splash-screen " ;
4+ import * as Font from " expo- font" ;
55import { Asset } from "expo-asset" ;
66import { Block , GalioProvider } from "galio-framework" ;
77import { NavigationContainer } from "@react-navigation/native" ;
@@ -21,14 +21,13 @@ const assetImages = [
2121 Images . Pro ,
2222 Images . ArgonLogo ,
2323 Images . iOSLogo ,
24- Images . androidLogo
24+ Images . androidLogo ,
2525] ;
26-
2726// cache product images
28- articles . map ( article => assetImages . push ( article . image ) ) ;
27+ articles . map ( ( article ) => assetImages . push ( article . image ) ) ;
2928
3029function cacheImages ( images ) {
31- return images . map ( image => {
30+ return images . map ( ( image ) => {
3231 if ( typeof image === "string" ) {
3332 return Image . prefetch ( image ) ;
3433 } else {
@@ -37,87 +36,49 @@ function cacheImages(images) {
3736 } ) ;
3837}
3938
40- export default props => {
41- const [ isLoadingComplete , setLoading ] = useState ( false ) ;
42- let [ fontsLoaded ] = useFonts ( {
43- 'ArgonExtra' : require ( './assets/font/argon.ttf' ) ,
44- } ) ;
39+ export default function App ( ) {
40+ const [ appIsReady , setAppIsReady ] = useState ( false ) ;
4541
46- function _loadResourcesAsync ( ) {
47- return Promise . all ( [ ...cacheImages ( assetImages ) ] ) ;
48- }
42+ useEffect ( ( ) => {
43+ async function prepare ( ) {
44+ try {
45+ //Load Resources
46+ await _loadResourcesAsync ( ) ;
47+ // Pre-load fonts, make any API calls you need to do here
48+ await Font . loadAsync ( {
49+ ArgonExtra : require ( "./assets/font/argon.ttf" ) ,
50+ } ) ;
51+ } catch ( e ) {
52+ console . warn ( e ) ;
53+ } finally {
54+ // Tell the application to render
55+ setAppIsReady ( true ) ;
56+ }
57+ }
58+ prepare ( ) ;
59+ } , [ ] ) ;
4960
50- function _handleLoadingError ( error ) {
51- // In this case, you might want to report the error to your error
52- // reporting service, for example Sentry
53- console . warn ( error ) ;
61+ const _loadResourcesAsync = async ( ) => {
62+ return Promise . all ( [ ...cacheImages ( assetImages ) ] ) ;
5463 } ;
5564
56- function _handleFinishLoading ( ) {
57- setLoading ( true ) ;
58- } ;
65+ const onLayoutRootView = useCallback ( async ( ) => {
66+ if ( appIsReady ) {
67+ await SplashScreen . hideAsync ( ) ;
68+ }
69+ } , [ appIsReady ] ) ;
5970
60- if ( ! fontsLoaded && ! isLoadingComplete ) {
61- return (
62- < AppLoading
63- startAsync = { _loadResourcesAsync }
64- onError = { _handleLoadingError }
65- onFinish = { _handleFinishLoading }
66- />
67- ) ;
68- } else if ( fontsLoaded ) {
69- return (
70- < NavigationContainer >
71- < GalioProvider theme = { argonTheme } >
72- < Block flex >
73- < Screens />
74- </ Block >
75- </ GalioProvider >
76- </ NavigationContainer >
77- ) ;
78- } else {
79- return null
71+ if ( ! appIsReady ) {
72+ return null ;
8073 }
81- }
82-
83- // export default class App extends React.Component {
84- // state = {
85- // isLoadingComplete: false
86- // };
87-
88- // render() {
89- // if (!this.state.isLoadingComplete) {
90- // return (
91- // <AppLoading
92- // startAsync={this._loadResourcesAsync}
93- // onError={this._handleLoadingError}
94- // onFinish={this._handleFinishLoading}
95- // />
96- // );
97- // } else {
98- // return (
99- // <NavigationContainer>
100- // <GalioProvider theme={argonTheme}>
101- // <Block flex>
102- // <Screens />
103- // </Block>
104- // </GalioProvider>
105- // </NavigationContainer>
106- // );
107- // }
108- // }
10974
110- // _loadResourcesAsync = async () => {
111- // return Promise.all([...cacheImages(assetImages)]);
112- // };
113-
114- // _handleLoadingError = error => {
115- // // In this case, you might want to report the error to your error
116- // // reporting service, for example Sentry
117- // console.warn(error);
118- // };
119-
120- // _handleFinishLoading = () => {
121- // this.setState({ isLoadingComplete: true });
122- // };
123- // }
75+ return (
76+ < NavigationContainer onReady = { onLayoutRootView } >
77+ < GalioProvider theme = { argonTheme } >
78+ < Block flex >
79+ < Screens />
80+ </ Block >
81+ </ GalioProvider >
82+ </ NavigationContainer >
83+ ) ;
84+ }
0 commit comments