|
| 1 | +import React from 'react'; |
| 2 | +import { Platform, StatusBar, StyleSheet, View } from 'react-native'; |
| 3 | +import { AppLoading, Asset, Font, Icon } from 'expo'; |
| 4 | +import AppNavigator from './navigation/AppNavigator'; |
| 5 | + |
| 6 | +export default class App extends React.Component { |
| 7 | + state = { |
| 8 | + isLoadingComplete: false, |
| 9 | + }; |
| 10 | + |
| 11 | + render() { |
| 12 | + if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) { |
| 13 | + return ( |
| 14 | + <AppLoading |
| 15 | + startAsync={this._loadResourcesAsync} |
| 16 | + onError={this._handleLoadingError} |
| 17 | + onFinish={this._handleFinishLoading} |
| 18 | + /> |
| 19 | + ); |
| 20 | + } else { |
| 21 | + return ( |
| 22 | + <View style={styles.container}> |
| 23 | + {Platform.OS === 'ios' && <StatusBar barStyle="default" />} |
| 24 | + <AppNavigator /> |
| 25 | + </View> |
| 26 | + ); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + _loadResourcesAsync = async () => { |
| 31 | + return Promise.all([ |
| 32 | + Asset.loadAsync([ |
| 33 | + require('./assets/images/robot-dev.png'), |
| 34 | + require('./assets/images/robot-prod.png'), |
| 35 | + ]), |
| 36 | + Font.loadAsync({ |
| 37 | + // This is the font that we are using for our tab bar |
| 38 | + ...Icon.Ionicons.font, |
| 39 | + // We include SpaceMono because we use it in HomeScreen.js. Feel free |
| 40 | + // to remove this if you are not using it in your app |
| 41 | + 'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'), |
| 42 | + }), |
| 43 | + ]); |
| 44 | + }; |
| 45 | + |
| 46 | + _handleLoadingError = error => { |
| 47 | + // In this case, you might want to report the error to your error |
| 48 | + // reporting service, for example Sentry |
| 49 | + console.warn(error); |
| 50 | + }; |
| 51 | + |
| 52 | + _handleFinishLoading = () => { |
| 53 | + this.setState({ isLoadingComplete: true }); |
| 54 | + }; |
| 55 | +} |
| 56 | + |
| 57 | +const styles = StyleSheet.create({ |
| 58 | + container: { |
| 59 | + flex: 1, |
| 60 | + backgroundColor: '#fff', |
| 61 | + }, |
| 62 | +}); |
0 commit comments