jellyfin-expo/App.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-12-12 21:22:47 +00:00
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* 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, { useEffect, useState } from 'react';
import { Platform, StatusBar } from 'react-native';
import { ThemeProvider } from 'react-native-elements';
2020-04-03 16:57:51 +00:00
import { AppLoading } from 'expo';
2019-08-19 06:47:46 +00:00
import { Asset } from 'expo-asset';
import * as Font from 'expo-font';
2020-04-03 16:57:51 +00:00
import * as ScreenOrientation from 'expo-screen-orientation';
2019-08-19 06:47:46 +00:00
import { Ionicons } from '@expo/vector-icons';
2019-08-29 04:38:29 +00:00
import PropTypes from 'prop-types';
2019-08-19 06:47:46 +00:00
import AppNavigator from './navigation/AppNavigator';
import Theme from './utils/Theme';
2019-08-19 06:47:46 +00:00
function App({ skipLoadingScreen }) {
const [isSplashReady, setIsSplashReady] = useState(false);
2019-08-19 06:47:46 +00:00
useEffect(() => {
2020-04-23 21:12:18 +00:00
// Lock portrait orientation on iPhone
if (Platform.OS === 'ios' && !Platform.isPad) {
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP);
2020-04-13 15:20:05 +00:00
}
}, []);
2019-08-19 06:47:46 +00:00
const loadImagesAsync = () => {
2020-04-13 15:20:05 +00:00
const images = [
require('./assets/images/splash.png'),
require('./assets/images/logowhite.png')
];
return images.map(image => Asset.fromModule(image).downloadAsync());
};
2019-08-19 06:47:46 +00:00
const loadResourcesAsync = async () => {
2020-04-13 15:20:05 +00:00
return Promise.all([
Font.loadAsync({
// This is the font that we are using for our tab bar
...Ionicons.font
}),
...loadImagesAsync()
2020-04-13 15:20:05 +00:00
]);
2019-08-19 06:47:46 +00:00
};
if (!isSplashReady && !skipLoadingScreen) {
return (
<AppLoading
startAsync={loadResourcesAsync}
onError={console.warn}
onFinish={() => setIsSplashReady(true)}
autoHideSplash={false}
/>
);
2020-04-13 15:20:05 +00:00
}
return (
<ThemeProvider theme={Theme}>
{Platform.OS === 'ios' && <StatusBar barStyle="light-content" />}
<AppNavigator />
</ThemeProvider>
);
}
App.propTypes = {
skipLoadingScreen: PropTypes.bool
};
export default App;