|
1 | | -import React from "react"; |
| 1 | +import React, {useState} from "react"; |
2 | 2 | import { Image } from "react-native"; |
3 | 3 | import { AppLoading } from "expo"; |
| 4 | +import { useFonts } from '@use-expo/font'; |
4 | 5 | import { Asset } from "expo-asset"; |
5 | 6 | import { Block, GalioProvider } from "galio-framework"; |
6 | 7 | import { NavigationContainer } from "@react-navigation/native"; |
@@ -36,44 +37,85 @@ function cacheImages(images) { |
36 | 37 | }); |
37 | 38 | } |
38 | 39 |
|
39 | | -export default class App extends React.Component { |
40 | | - state = { |
41 | | - isLoadingComplete: false |
42 | | - }; |
43 | | - |
44 | | - render() { |
45 | | - if (!this.state.isLoadingComplete) { |
46 | | - return ( |
47 | | - <AppLoading |
48 | | - startAsync={this._loadResourcesAsync} |
49 | | - onError={this._handleLoadingError} |
50 | | - onFinish={this._handleFinishLoading} |
51 | | - /> |
52 | | - ); |
53 | | - } else { |
54 | | - return ( |
55 | | - <NavigationContainer> |
56 | | - <GalioProvider theme={argonTheme}> |
57 | | - <Block flex> |
58 | | - <Screens /> |
59 | | - </Block> |
60 | | - </GalioProvider> |
61 | | - </NavigationContainer> |
62 | | - ); |
63 | | - } |
64 | | - } |
| 40 | +export default props => { |
| 41 | + const [isLoadingComplete, setLoading] = useState(false); |
| 42 | + let [fontsLoaded] = useFonts({ |
| 43 | + 'ArgonExtra': require('./assets/font/argon.ttf'), |
| 44 | + }); |
65 | 45 |
|
66 | | - _loadResourcesAsync = async () => { |
| 46 | + function _loadResourcesAsync() { |
67 | 47 | return Promise.all([...cacheImages(assetImages)]); |
68 | | - }; |
| 48 | + } |
69 | 49 |
|
70 | | - _handleLoadingError = error => { |
| 50 | + function _handleLoadingError(error) { |
71 | 51 | // In this case, you might want to report the error to your error |
72 | 52 | // reporting service, for example Sentry |
73 | 53 | console.warn(error); |
74 | 54 | }; |
75 | 55 |
|
76 | | - _handleFinishLoading = () => { |
77 | | - this.setState({ isLoadingComplete: true }); |
| 56 | + function _handleFinishLoading() { |
| 57 | + setLoading(true); |
78 | 58 | }; |
| 59 | + |
| 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 | + } |
79 | 79 | } |
| 80 | + |
| 81 | +// export default class App extends React.Component { |
| 82 | +// state = { |
| 83 | +// isLoadingComplete: false |
| 84 | +// }; |
| 85 | + |
| 86 | +// render() { |
| 87 | +// if (!this.state.isLoadingComplete) { |
| 88 | +// return ( |
| 89 | +// <AppLoading |
| 90 | +// startAsync={this._loadResourcesAsync} |
| 91 | +// onError={this._handleLoadingError} |
| 92 | +// onFinish={this._handleFinishLoading} |
| 93 | +// /> |
| 94 | +// ); |
| 95 | +// } else { |
| 96 | +// return ( |
| 97 | +// <NavigationContainer> |
| 98 | +// <GalioProvider theme={argonTheme}> |
| 99 | +// <Block flex> |
| 100 | +// <Screens /> |
| 101 | +// </Block> |
| 102 | +// </GalioProvider> |
| 103 | +// </NavigationContainer> |
| 104 | +// ); |
| 105 | +// } |
| 106 | +// } |
| 107 | + |
| 108 | +// _loadResourcesAsync = async () => { |
| 109 | +// return Promise.all([...cacheImages(assetImages)]); |
| 110 | +// }; |
| 111 | + |
| 112 | +// _handleLoadingError = error => { |
| 113 | +// // In this case, you might want to report the error to your error |
| 114 | +// // reporting service, for example Sentry |
| 115 | +// console.warn(error); |
| 116 | +// }; |
| 117 | + |
| 118 | +// _handleFinishLoading = () => { |
| 119 | +// this.setState({ isLoadingComplete: true }); |
| 120 | +// }; |
| 121 | +// } |
0 commit comments