From 75ab5753222e5756228ee0dfe3d958850e104ed1 Mon Sep 17 00:00:00 2001 From: keplyx Date: Tue, 20 Aug 2019 20:00:34 +0200 Subject: [PATCH] Show splash screen when app not finished loading instead of basic view --- App.js | 58 +++++++++++++++++++++++++++++++------------------------- app.json | 2 +- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/App.js b/App.js index e61f1c1..d7f7d69 100644 --- a/App.js +++ b/App.js @@ -2,7 +2,6 @@ import * as React from 'react'; import {Root, StyleProvider} from 'native-base'; -import {View} from 'react-native' import AppNavigator from './navigation/AppNavigator'; import ThemeManager from './utils/ThemeManager'; import LocaleManager from './utils/LocaleManager'; @@ -13,7 +12,7 @@ import * as Font from 'expo-font'; import {clearThemeCache} from 'native-base-shoutem-theme'; import AsyncStorageManager from "./utils/AsyncStorageManager"; import CustomIntroSlider from "./components/CustomIntroSlider"; -import {Notifications} from 'expo'; +import {AppLoading} from 'expo'; import NotificationsManager from "./utils/NotificationsManager"; type Props = {}; @@ -37,29 +36,6 @@ export default class App extends React.Component { LocaleManager.initTranslations(); } - /** - * Loads FetchedData before components are mounted, like fonts and themes - * @returns {Promise} - */ - async componentWillMount() { - // Wait for custom fonts to be loaded before showing the app - await Font.loadAsync({ - 'Roboto': require('native-base/Fonts/Roboto.ttf'), - 'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'), - }); - await AsyncStorageManager.getInstance().loadPreferences(); - ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme()); - await NotificationsManager.initExpoToken(); - console.log(AsyncStorageManager.getInstance().preferences.expoToken.current); - // Only show intro if this is the first time starting the app - this.setState({ - isLoading: false, - currentTheme: ThemeManager.getCurrentTheme(), - showIntro: AsyncStorageManager.getInstance().preferences.showIntro.current === '1' - // showIntro: true - }); - } - /** * Updates the theme and clears the cache to force reloading the app colors. Need to edit shoutem theme for ti to work */ @@ -78,12 +54,42 @@ export default class App extends React.Component { AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0'); } + async loadAssetsAsync() { + console.log('Starting loading assets...'); + // Wait for custom fonts to be loaded before showing the app + await Font.loadAsync({ + 'Roboto': require('native-base/Fonts/Roboto.ttf'), + 'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'), + }); + await AsyncStorageManager.getInstance().loadPreferences(); + ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme()); + await NotificationsManager.initExpoToken(); + console.log(AsyncStorageManager.getInstance().preferences.expoToken.current); + } + + onLoadFinished() { + // Only show intro if this is the first time starting the app + console.log('Finished loading'); + this.setState({ + isLoading: false, + currentTheme: ThemeManager.getCurrentTheme(), + showIntro: AsyncStorageManager.getInstance().preferences.showIntro.current === '1' + // showIntro: true + }); + } + /** * Renders the app based on loading state */ render() { if (this.state.isLoading) { - return ; + return ( + this.onLoadFinished()} + onError={console.warn} + /> + ); } if (this.state.showIntro) { return this.onIntroDone()}/>; diff --git a/app.json b/app.json index 12852e3..856c730 100644 --- a/app.json +++ b/app.json @@ -10,7 +10,7 @@ "android", "web" ], - "version": "0.0.9", + "version": "0.0.10", "orientation": "portrait", "primaryColor": "#be1522", "icon": "./assets/android.icon.png",