Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup App component #89

Merged
merged 1 commit into from
Jun 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 33 additions & 44 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import { Platform, StatusBar, StyleSheet, View } from 'react-native';
import React, { useEffect, useState } from 'react';
import { Platform, StatusBar } from 'react-native';
import { ThemeProvider } from 'react-native-elements';
import { AppLoading } from 'expo';
import { Asset } from 'expo-asset';
Expand All @@ -14,68 +14,57 @@ import { Ionicons } from '@expo/vector-icons';
import PropTypes from 'prop-types';

import AppNavigator from './navigation/AppNavigator';
import Colors from './constants/Colors';
import Theme from './utils/Theme';

export default class App extends React.Component {
static propTypes = {
skipLoadingScreen: PropTypes.bool
};

state = {
isSplashReady: false
};
function App({ skipLoadingScreen }) {
const [isSplashReady, setIsSplashReady] = useState(false);

componentDidMount() {
useEffect(() => {
// Lock portrait orientation on iPhone
if (Platform.OS === 'ios' && !Platform.isPad) {
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP);
}
}

render() {
if (!this.state.isSplashReady && !this.props.skipLoadingScreen) {
return (
<AppLoading
startAsync={this._loadResourcesAsync}
onError={console.warn}
onFinish={() => this.setState({ isSplashReady: true })}
autoHideSplash={false}
/>
);
}
return (
<ThemeProvider theme={Theme}>
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="light-content" />}
<AppNavigator />
</View>
</ThemeProvider>
);
}
}, []);

_loadImagesAsync = () => {
const loadImagesAsync = () => {
const images = [
require('./assets/images/splash.png'),
require('./assets/images/logowhite.png')
];
return images.map(image => Asset.fromModule(image).downloadAsync());
}
};

_loadResourcesAsync = async () => {
const loadResourcesAsync = async () => {
return Promise.all([
Font.loadAsync({
// This is the font that we are using for our tab bar
...Ionicons.font
}),
...this._loadImagesAsync()
...loadImagesAsync()
]);
};
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.backgroundColor
if (!isSplashReady && !skipLoadingScreen) {
return (
<AppLoading
startAsync={loadResourcesAsync}
onError={console.warn}
onFinish={() => setIsSplashReady(true)}
autoHideSplash={false}
/>
);
}
});

return (
<ThemeProvider theme={Theme}>
{Platform.OS === 'ios' && <StatusBar barStyle="light-content" />}
<AppNavigator />
</ThemeProvider>
);
}

App.propTypes = {
skipLoadingScreen: PropTypes.bool
};

export default App;